From 66d3bd4a3cf9a31165485ea590d94aa0971facac Mon Sep 17 00:00:00 2001 From: Jacob Baskin Date: Thu, 26 Jan 2017 14:32:36 -0500 Subject: [PATCH 1/3] Add typings for moment-round --- moment-round/index.d.ts | 14 ++++++++++++++ moment-round/moment-round-tests.ts | 8 ++++++++ moment-round/tsconfig.json | 20 ++++++++++++++++++++ moment-round/tslint.json | 1 + 4 files changed, 43 insertions(+) create mode 100644 moment-round/index.d.ts create mode 100644 moment-round/moment-round-tests.ts create mode 100644 moment-round/tsconfig.json create mode 100644 moment-round/tslint.json diff --git a/moment-round/index.d.ts b/moment-round/index.d.ts new file mode 100644 index 0000000000..e68181ac34 --- /dev/null +++ b/moment-round/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for moment-round 1.0 +// Project: https://github.com/WebDevTmas/moment-round +// Definitions by: Jacob Baskin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as moment from 'moment'; + +declare module 'moment' { + interface Moment { + round(precision: number, key: string, direction: 'round' | 'ceil' | 'floor'): Moment; + ceil(precision: number, key: string): Moment; + floor(precision: number, key: string): Moment; + } +} diff --git a/moment-round/moment-round-tests.ts b/moment-round/moment-round-tests.ts new file mode 100644 index 0000000000..6925966365 --- /dev/null +++ b/moment-round/moment-round-tests.ts @@ -0,0 +1,8 @@ +import * as moment from 'moment'; + +var m = new moment(); // 2015-06-18 15:30:19 +moment.round(5, 'seconds'); // 2015-06-18 15:30:20 +moment.ceil(3, 'minutes'); // 2015-06-18 15:33:00 +moment.floor(16, 'hours'); // 2015-06-18 00:00:00 +moment.ceil(21, 'hours'); // 2015-06-18 21:00:00 +moment.ceil(20, 'hours'); // 2015-06-19 00:00:00 diff --git a/moment-round/tsconfig.json b/moment-round/tsconfig.json new file mode 100644 index 0000000000..7054df992f --- /dev/null +++ b/moment-round/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "moment-round-tests.ts" + ] +} diff --git a/moment-round/tslint.json b/moment-round/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/moment-round/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From f4a5b2bfb5d35876d87b9484762926f9e8c571a5 Mon Sep 17 00:00:00 2001 From: Jacob Baskin Date: Thu, 26 Jan 2017 14:36:39 -0500 Subject: [PATCH 2/3] Add 'export = moment' --- moment-round/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moment-round/index.d.ts b/moment-round/index.d.ts index e68181ac34..8e6ac65cf5 100644 --- a/moment-round/index.d.ts +++ b/moment-round/index.d.ts @@ -5,6 +5,8 @@ import * as moment from 'moment'; +export = moment; + declare module 'moment' { interface Moment { round(precision: number, key: string, direction: 'round' | 'ceil' | 'floor'): Moment; From fab0c1b8dd929e38bc58f569149a34b153eec477 Mon Sep 17 00:00:00 2001 From: Jacob Baskin Date: Thu, 26 Jan 2017 14:43:58 -0500 Subject: [PATCH 3/3] Fix moment-round typings --- moment-round/index.d.ts | 2 +- moment-round/moment-round-tests.ts | 12 ++++++------ moment-round/package.json | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 moment-round/package.json diff --git a/moment-round/index.d.ts b/moment-round/index.d.ts index 8e6ac65cf5..441cec3f6f 100644 --- a/moment-round/index.d.ts +++ b/moment-round/index.d.ts @@ -9,7 +9,7 @@ export = moment; declare module 'moment' { interface Moment { - round(precision: number, key: string, direction: 'round' | 'ceil' | 'floor'): Moment; + round(precision: number, key: string, direction?: 'round' | 'ceil' | 'floor'): Moment; ceil(precision: number, key: string): Moment; floor(precision: number, key: string): Moment; } diff --git a/moment-round/moment-round-tests.ts b/moment-round/moment-round-tests.ts index 6925966365..063e3cbea4 100644 --- a/moment-round/moment-round-tests.ts +++ b/moment-round/moment-round-tests.ts @@ -1,8 +1,8 @@ import * as moment from 'moment'; -var m = new moment(); // 2015-06-18 15:30:19 -moment.round(5, 'seconds'); // 2015-06-18 15:30:20 -moment.ceil(3, 'minutes'); // 2015-06-18 15:33:00 -moment.floor(16, 'hours'); // 2015-06-18 00:00:00 -moment.ceil(21, 'hours'); // 2015-06-18 21:00:00 -moment.ceil(20, 'hours'); // 2015-06-19 00:00:00 +var m = moment(); +m.round(5, 'seconds'); +m.ceil(3, 'minutes'); +m.floor(16, 'hours'); +m.ceil(21, 'hours'); +m.ceil(20, 'hours'); diff --git a/moment-round/package.json b/moment-round/package.json new file mode 100644 index 0000000000..4c6d24a445 --- /dev/null +++ b/moment-round/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "moment": ">=2.14.0" + } +} \ No newline at end of file