Merge pull request #21097 from rwdalpe/moment-holiday

Adding typings for moment-holiday
This commit is contained in:
Daniel Rosenwasser
2017-11-07 00:36:25 -08:00
committed by GitHub
5 changed files with 228 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
// Type definitions for moment-holiday 1.5
// Project: https://github.com/kodie/moment-holiday
// Definitions by: Robert Winslow Dalpe <https://github.com/rwdalpe>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as moment from 'moment';
declare module 'moment' {
interface Moment extends Object {
holiday(
holidays?: string[] | string,
adjust?: boolean): Moment | false | { [holidayName: string]: Moment };
holidays(
holidays?: string[] | string,
adjust?: boolean): Moment | false | { [holidayName: string]: Moment };
isHoliday(
holidays?: string[] | string | null,
adjust?: boolean): boolean | string | string[];
previousHoliday(count?: number, adjust?: boolean): Moment[] | Moment;
previousHolidays(count?: number, adjust?: boolean): Moment[] | Moment;
nextHoliday(count?: number, adjust?: boolean): Moment[] | Moment;
nextHolidays(count?: number, adjust?: boolean): Moment[] | Moment;
holidaysBetween(m: Moment, adjust?: boolean): Moment[] | false;
}
interface HolidayDefinition {
date: string;
keywords?: string[];
keywords_y?: string[];
keywords_n?: string[];
regions?: string[];
regions_n?: string[];
}
interface HolidaysMapping {
[holidayName: string]: HolidayDefinition;
}
interface Holidays {
active: HolidaysMapping;
active_last: HolidaysMapping;
}
interface HolidayModifier {
set(
holidays: HolidaysMapping | string | string[],
specifics?: any): HolidayModifier;
add(
holidays: HolidaysMapping | string,
specifics?: any): HolidayModifier;
remove(holidays: string | string[]): HolidayModifier;
undo(): HolidayModifier;
load(locales: string | string[]): HolidayModifier;
extendParser(parserFunc: (m: Moment, date: string) => Moment | Moment[] | false | void): HolidayModifier;
}
let holidays: Holidays;
let modifyHolidays: HolidayModifier;
}
@@ -0,0 +1,127 @@
import moment = require('moment');
import 'moment-holiday';
let holidayResult: moment.Moment | false | { [holidayName: string]: moment.Moment };
holidayResult = moment().holiday([]);
holidayResult = moment().holiday([], false);
holidayResult = moment().holiday([], true);
holidayResult = moment().holiday('string');
holidayResult = moment().holiday('string', false);
holidayResult = moment().holiday('string', true);
holidayResult = moment().holiday(['array', 'of', 'strings']);
holidayResult = moment().holiday(['array', 'of', 'strings'], false);
holidayResult = moment().holiday(['array', 'of', 'strings'], true);
holidayResult = moment().holidays([]);
holidayResult = moment().holidays([], false);
holidayResult = moment().holidays([], true);
holidayResult = moment().holidays('string');
holidayResult = moment().holidays('string', false);
holidayResult = moment().holidays('string', true);
holidayResult = moment().holidays(['array', 'of', 'strings']);
holidayResult = moment().holidays(['array', 'of', 'strings'], false);
holidayResult = moment().holidays(['array', 'of', 'strings'], true);
let isHolidayResult: boolean | string | string[];
isHolidayResult = moment().isHoliday();
isHolidayResult = moment().isHoliday([]);
isHolidayResult = moment().isHoliday([], false);
isHolidayResult = moment().isHoliday([], true);
isHolidayResult = moment().isHoliday(['array', 'of', 'strings']);
isHolidayResult = moment().isHoliday(['array', 'of', 'strings'], false);
isHolidayResult = moment().isHoliday(['array', 'of', 'strings'], true);
isHolidayResult = moment().isHoliday('string');
isHolidayResult = moment().isHoliday('string', false);
isHolidayResult = moment().isHoliday('string', true);
isHolidayResult = moment().isHoliday(null);
isHolidayResult = moment().isHoliday(null, false);
isHolidayResult = moment().isHoliday(null, true);
let previousHolidayResult: moment.Moment[] | moment.Moment;
previousHolidayResult = moment().previousHoliday();
previousHolidayResult = moment().previousHoliday(1);
previousHolidayResult = moment().previousHoliday(1, false);
previousHolidayResult = moment().previousHoliday(1, true);
previousHolidayResult = moment().previousHolidays();
previousHolidayResult = moment().previousHolidays(1);
previousHolidayResult = moment().previousHolidays(1, false);
previousHolidayResult = moment().previousHolidays(1, true);
let nextHolidayResult: moment.Moment[] | moment.Moment;
nextHolidayResult = moment().nextHoliday();
nextHolidayResult = moment().nextHoliday(1);
nextHolidayResult = moment().nextHoliday(1, false);
nextHolidayResult = moment().nextHoliday(1, true);
nextHolidayResult = moment().nextHolidays();
nextHolidayResult = moment().nextHolidays(1);
nextHolidayResult = moment().nextHolidays(1, false);
nextHolidayResult = moment().nextHolidays(1, true);
let holidaysBetweenResult: moment.Moment[] | false;
holidaysBetweenResult = moment().holidaysBetween(moment());
holidaysBetweenResult = moment().holidaysBetween(moment(), false);
holidaysBetweenResult = moment().holidaysBetween(moment(), true);
let holidayDefinition: moment.HolidayDefinition = {
date: 'string'
};
holidayDefinition = {
date: 'string',
keywords: ['array'],
};
holidayDefinition = {
date: 'string',
keywords: ['array'],
keywords_n: ['array'],
};
holidayDefinition = {
date: 'string',
keywords: ['array'],
keywords_n: ['array'],
keywords_y: ['array'],
};
holidayDefinition = {
date: 'string',
keywords: ['array'],
keywords_n: ['array'],
keywords_y: ['array'],
regions: ['array'],
};
holidayDefinition = {
date: 'string',
keywords: ['array'],
keywords_n: ['array'],
keywords_y: ['array'],
regions: ['array'],
regions_n: ['array']
};
const holidays: moment.Holidays = moment.holidays;
let activeHolidays: moment.HolidaysMapping = moment.holidays.active;
activeHolidays = {
'Some holiday name': holidayDefinition
};
let lastActiveHolidays: moment.HolidaysMapping = moment.holidays.active_last;
lastActiveHolidays = {
'Some holiday name': holidayDefinition
};
let holidayModifier: moment.HolidayModifier = moment.modifyHolidays;
holidayModifier = holidayModifier.set('string');
holidayModifier = holidayModifier.set(['array']);
holidayModifier = holidayModifier.set(activeHolidays);
holidayModifier = holidayModifier.set('string', {});
holidayModifier = holidayModifier.set(['array'], {});
holidayModifier = holidayModifier.set(activeHolidays, {});
holidayModifier = holidayModifier.add(activeHolidays);
holidayModifier = holidayModifier.add('string');
holidayModifier = holidayModifier.add(activeHolidays, {});
holidayModifier = holidayModifier.add('string', {});
holidayModifier = holidayModifier.remove('string');
holidayModifier = holidayModifier.remove(['array']);
holidayModifier = holidayModifier.undo();
holidayModifier = holidayModifier.load('string');
holidayModifier = holidayModifier.load(['string']);
holidayModifier = holidayModifier.extendParser((m: moment.Moment, d: string): moment.Moment | moment.Moment[] | false | void => {
});
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"moment": ">=2.0.0"
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"moment-holiday-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }