diff --git a/types/moment-shortformat/index.d.ts b/types/moment-shortformat/index.d.ts new file mode 100644 index 0000000000..d5125aac49 --- /dev/null +++ b/types/moment-shortformat/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for moment-shortformat 2.1 +// Project: https://github.com/researchgate/moment-shortformat#readme +// Definitions by: whatasoda +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace moment; + +import moment = require('moment'); + +export = moment; + +declare module 'moment' { + interface Moment { + short(withoutPreOrSuffix?: boolean, now?: Moment): string; + } +} diff --git a/types/moment-shortformat/moment-shortformat-tests.ts b/types/moment-shortformat/moment-shortformat-tests.ts new file mode 100644 index 0000000000..84f754a750 --- /dev/null +++ b/types/moment-shortformat/moment-shortformat-tests.ts @@ -0,0 +1,20 @@ +import moment = require('moment'); +import 'moment-shortformat'; + +let formatted: string; +/*~ Formats time relative to current time. */ +formatted = moment(moment().valueOf() + (36e5 * 5)).short(); // 'in 5h' +formatted = moment(moment().valueOf() - (36e5 * 5)).short(); // '5h ago' +formatted = moment(moment().valueOf() + (36e5 * 5)).short(true); // '5h' +formatted = moment(moment().valueOf() - (36e5 * 5)).short(true); // '5h' + +/*~ Times greater than 1 week are converted to dates like Mar 7, + *~ or if the year of the date does not match the current year + *~ it is convert to Mar 7, 2031 + */ +formatted = moment(moment().valueOf() + 6048e5).short(); // 'Mar 7' + +/*~ Using a different "now" */ +formatted = moment(moment().valueOf() + (36e5 * 5)).short( + false, moment(moment().valueOf() + (36e5 * 3)) +); // 'in 2h' diff --git a/types/moment-shortformat/tsconfig.json b/types/moment-shortformat/tsconfig.json new file mode 100644 index 0000000000..96fd6c6524 --- /dev/null +++ b/types/moment-shortformat/tsconfig.json @@ -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-shortformat-tests.ts" + ] +} diff --git a/types/moment-shortformat/tslint.json b/types/moment-shortformat/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/moment-shortformat/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }