Merge branch 'QuatroTypings-master'

This commit is contained in:
Nathan Shively-Sanders
2017-06-22 14:07:40 -07:00
6 changed files with 103 additions and 119 deletions
+40 -77
View File
@@ -1,104 +1,67 @@
// Type definitions for Moment-range.js 3.0
// Project: https://github.com/gf3/moment-range
// Definitions by: Bart van den Burg <https://github.com/Burgov>, Wilgert Velinga <https://github.com/wilgert>, Juan Francisco Adame <https://github.com/franjuan>
// Definitions by: Bart van den Burg <https://github.com/Burgov>
// Wilgert Velinga <https://github.com/wilgert>
// Juan Francisco Adame <https://github.com/franjuan>
// MartynasZilinskas <https://github.com/MartynasZilinskas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as moment from 'moment';
export = moment;
export class DateRange {
start: moment.Moment;
end: moment.Moment;
declare module 'moment' {
class DateRange implements Range {
start: Moment;
end: Moment;
constructor(range: string | Date[] | moment.Moment[]);
constructor(start: Date | moment.Moment, end: Date | moment.Moment);
constructor(range: string | Date[] | Moment[]);
constructor(start: Date | Moment, end: Date | Moment);
contains(other: DateRange | moment.Moment | Date, options?: { exclusive?: boolean }): boolean;
contains(other: DateRange | Moment | Date, options?: { exclusive?: boolean }): boolean;
overlaps(range: DateRange, options?: { adjacent?: boolean }): boolean;
overlaps(range: DateRange, options?: { adjacent?: boolean }): boolean;
intersect(other: DateRange): DateRange;
intersect(other: DateRange): DateRange;
add(other: DateRange): DateRange;
add(other: DateRange): DateRange;
subtract(other: DateRange): DateRange[];
subtract(other: DateRange): DateRange[];
by(interval: moment.unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<moment.Moment>;
by(interval: unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
byRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<moment.Moment>;
byRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
isSame(other: DateRange): boolean;
isSame(other: DateRange): boolean;
diff(unit?: moment.unitOfTime.Diff, rounded?: boolean): number;
diff(unit?: unitOfTime.Diff, rounded?: boolean): number;
toDate(): Date[];
toDate(): Date[];
toString(): string;
toString(): string;
valueOf(): number;
valueOf(): number;
center(): moment.Moment;
center(): Moment;
clone(): DateRange;
clone(): DateRange;
isEqual(other: DateRange): boolean;
isEqual(other: DateRange): boolean;
adjacent(other: DateRange): boolean;
adjacent(other: DateRange): boolean;
duration(unit?: moment.unitOfTime.Diff, precise?: boolean): number;
duration(unit?: unitOfTime.Diff, precise?: boolean): number;
reverseBy(interval: moment.unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<moment.Moment>;
reverseBy(interval: unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
reverseByRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
}
interface Range {
start: Moment;
end: Moment;
contains(other: DateRange | Moment | Date, options?: { exclusive?: boolean }): boolean;
overlaps(range: DateRange, options?: { adjacent?: boolean }): boolean;
intersect(other: DateRange): DateRange;
add(other: DateRange): DateRange;
subtract(other: DateRange): DateRange[];
by(interval: unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
byRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
isSame(other: DateRange): boolean;
diff(unit?: unitOfTime.Diff, rounded?: boolean): number;
toDate(): Date[];
toString(): string;
valueOf(): number;
center(): Moment;
clone(): DateRange;
isEqual(other: DateRange): boolean;
adjacent(other: DateRange): boolean;
duration(unit?: unitOfTime.Diff, precise?: boolean): number;
reverseBy(interval: unitOfTime.Diff, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
reverseByRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<Moment>;
}
function extendMoment(moment: any): any;
function range(range: string | Date[] | Moment[]): Range;
function range(start: Date | Moment, end: Date | Moment): Range;
reverseByRange(interval: DateRange, options?: { exclusive?: boolean, step?: number }): Iterable<moment.Moment>;
}
export interface MomentRangeMethods {
range(range: string | Date[] | moment.Moment[]): DateRange;
range(start: Date | moment.Moment, end: Date | moment.Moment): DateRange;
within(range: DateRange): boolean;
}
export interface MomentRangeExtends extends MomentRangeMethods {
(...args: any[]): MomentRangeMethods & moment.Moment;
}
export function extendMoment(momentInstance: moment.Moment | typeof moment): MomentRangeExtends & moment.Moment;
+24 -13
View File
@@ -1,7 +1,14 @@
import * as moment from 'moment';
import * as moment from "moment";
import * as momentRange from "moment-range";
const range: momentRange.DateRange = new momentRange.DateRange(new Date(2012, 0, 15), new Date(2012, 4, 23));
const extendedMoment = momentRange.extendMoment(moment);
// Moment methods test
extendedMoment.add();
extendedMoment().add();
const range2: momentRange.DateRange = new momentRange.DateRange(moment("2011-04-15", "YYYY-MM-DD"), moment("2011-11-27", "YYYY-MM-DD"));
const range3: momentRange.DateRange = new momentRange.DateRange([moment("2011-04-15", "YYYY-MM-DD"), moment("2011-11-27", "YYYY-MM-DD")]);
const range4: momentRange.DateRange = new momentRange.DateRange("2015-01-17T09:50:04+00:00/2015-04-17T08:29:55+00:00");
@@ -11,20 +18,20 @@ const date: moment.Moment = moment('2012-05-15');
const res1: boolean = range.adjacent(range2);
const it0: Iterable<moment.Moment> = range.by('days');
const it1: Iterable<moment.Moment> = range.by('months', {exclusive: true});
const it2: Iterable<moment.Moment> = range.by('years', {exclusive: false, step: 2});
const it1: Iterable<moment.Moment> = range.by('months', { exclusive: true });
const it2: Iterable<moment.Moment> = range.by('years', { exclusive: false, step: 2 });
const it3: Iterable<moment.Moment> = range.byRange(range);
const it4: Iterable<moment.Moment> = range.byRange(range, {exclusive: true});
const it5: Iterable<moment.Moment> = range.byRange(range, {exclusive: false, step: 2});
const it4: Iterable<moment.Moment> = range.byRange(range, { exclusive: true });
const it5: Iterable<moment.Moment> = range.byRange(range, { exclusive: false, step: 2 });
const res2: moment.Moment = range.center();
const res3: momentRange.DateRange = range.clone();
const res4: boolean = range.contains(range);
const res5: boolean = range.contains(range, {exclusive: true});
const res6: boolean = range.contains(range, {exclusive: false});
const res5: boolean = range.contains(range, { exclusive: true });
const res6: boolean = range.contains(range, { exclusive: false });
const res10: number = range.diff('months', true);
const res11: number = range.diff('days');
@@ -41,16 +48,16 @@ const res17: boolean = range.isSame(range2);
const res18: boolean = range.isEqual(range2);
const res20: boolean = range.overlaps(range2);
const res21: boolean = range.overlaps(range2, {adjacent: true});
const res22: boolean = range.overlaps(range2, {adjacent: false});
const res21: boolean = range.overlaps(range2, { adjacent: true });
const res22: boolean = range.overlaps(range2, { adjacent: false });
const it6: Iterable<moment.Moment> = range.reverseBy('days');
const it7: Iterable<moment.Moment> = range.reverseBy('months', {exclusive: true});
const it8: Iterable<moment.Moment> = range.reverseBy('years', {exclusive: false, step: 2});
const it7: Iterable<moment.Moment> = range.reverseBy('months', { exclusive: true });
const it8: Iterable<moment.Moment> = range.reverseBy('years', { exclusive: false, step: 2 });
const it9: Iterable<moment.Moment> = range.reverseByRange(range);
const it10: Iterable<moment.Moment> = range.reverseByRange(range, {exclusive: true});
const it11: Iterable<moment.Moment> = range.reverseByRange(range, {exclusive: false, step: 2});
const it10: Iterable<moment.Moment> = range.reverseByRange(range, { exclusive: true });
const it11: Iterable<moment.Moment> = range.reverseByRange(range, { exclusive: false, step: 2 });
const res23: momentRange.DateRange = range.add(range2);
@@ -64,3 +71,7 @@ const res27: number = range.valueOf();
const res28: moment.Moment = range.start;
const res29: moment.Moment = range.end;
const res30: boolean = extendedMoment.within(range);
const res31: boolean = extendedMoment().within(range);
const res32: momentRange.DateRange = extendedMoment().range(moment("2011-04-15", "YYYY-MM-DD"), moment("2011-11-27", "YYYY-MM-DD"));
+15 -15
View File
@@ -1,16 +1,18 @@
// Type definitions for React Daterange Picker v1.1.0
// Type definitions for React Daterange Picker 1.1
// Project: https://github.com/onefinestay/react-daterange-picker
// Definitions by: UNCOVER TRUTH Inc. <https://github.com/uncovertruth/>
// MartynasZilinskas <https://github.com/MartynasZilinskas>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 2.3
import * as React from "react";
import * as moment from "moment-range";
import * as moment from "moment";
import * as momentRange from "moment-range";
export default class DateRangePicker extends React.Component<Props> {}
export default class DateRangePicker extends React.Component<Props> { }
export as namespace ReactDateRangePicker;
interface Props extends React.Props<{}> {
export interface Props extends React.Props<{}> {
bemBlock?: string;
bemNamespace?: string;
dateStates?: DateState[];
@@ -30,37 +32,35 @@ interface Props extends React.Props<{}> {
onHighlightDate?(date: Date): void;
onHighlightRange?(date: Date): void;
onSelect?(value: Props): void;
onSelectStart?(value: moment.Moment): void;
onSelectStart?(value: momentRange.MomentRangeExtends): void;
paginationArrowComponent?: PaginationArrow;
selectedLabel?: string;
selectionType?: 'single' |'range';
selectionType?: 'single' | 'range';
singleDateRange?: boolean;
showLegend?: boolean;
stateDefinitions?: StateDefinitions;
value?: moment.Moment | moment.Range;
value?: momentRange.MomentRangeExtends | momentRange.DateRange;
}
interface DateState {
export interface DateState {
state: string;
range: moment.Range;
range: momentRange.DateRange;
}
interface StateDefinitions {
export interface StateDefinitions {
[key: string]: StateDefinition;
}
interface StateDefinition {
export interface StateDefinition {
color: string;
label: string;
selectable?: boolean;
}
interface PaginationArrowProps extends React.Props<{}> {
export interface PaginationArrowProps extends React.Props<{}> {
disabled?: boolean;
onTrigger?(): void;
direction?: 'next' | 'previous';
}
declare class PaginationArrow extends React.Component<PaginationArrowProps> {
}
export class PaginationArrow extends React.Component<PaginationArrowProps> { }
@@ -0,0 +1,5 @@
{
"dependencies": {
"moment": "^2.18.1"
}
}
@@ -1,12 +1,15 @@
// Test app from https://github.com/onefinestay/react-daterange-picker/blob/master/example/index.jsx
// test app from https://github.com/onefinestay/react-daterange-picker/blob/master/example/index.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as moment from 'moment-range';
import DateRangePicker from "react-daterange-picker";
import * as ReactDateRangePicker from "react-daterange-picker";
interface AppProps extends ReactDateRangePicker.Props {
}
import * as MomentRange from "moment-range";
import * as Moment from "moment";
const moment = MomentRange.extendMoment(Moment);
type AppProps = ReactDateRangePicker.Props;
class App extends React.Component<AppProps, any> {
constructor(props: AppProps, context: any) {
@@ -16,7 +19,7 @@ class App extends React.Component<AppProps, any> {
}
handleSelect(value: AppProps, states: any): void {
this.setState({value, states});
this.setState({ value, states });
}
render(): any {
@@ -29,8 +32,8 @@ class App extends React.Component<AppProps, any> {
<input type="text"
value={this.state.value ? this.state.value.start.format('LL') : ""}
readOnly={true}
placeholder="Start date"/>
<input type="text"
placeholder="Start date" />
<input type="text"
value={this.state.value ? this.state.value.end.format('LL') : ""}
readOnly={true}
placeholder="End date" />
@@ -41,25 +44,25 @@ class App extends React.Component<AppProps, any> {
}
class DateSinglePicker extends React.Component<AppProps, any> {
constructor(props : AppProps, context: any) {
constructor(props: AppProps, context: any) {
super(props, context);
this.state = {};
}
handleSelect(value: AppProps) {
this.setState({value: value});
this.setState({ value });
}
render() {
return (
<div>
<DateRangePicker {...this.props} onSelect={this.handleSelect.bind(this)}
value={this.state.value} />
value={this.state.value} />
<div>
<input type="text"
value={this.state.value ? this.state.value.format('LL') : ""}
readOnly={true} />
<input type="text"
value={this.state.value ? this.state.value.format('LL') : ""}
readOnly={true} />
</div>
</div>
);
@@ -67,7 +70,6 @@ class DateSinglePicker extends React.Component<AppProps, any> {
}
export class Main extends React.Component {
render() {
const stateDefinitions: ReactDateRangePicker.StateDefinitions = {
available: {
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}