mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 19:12:20 +08:00
Merge pull request #26478 from whatasoda/moment-shortformat
Added declaration of moment-shortformat
This commit is contained in:
16
types/moment-shortformat/index.d.ts
vendored
Normal file
16
types/moment-shortformat/index.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// Type definitions for moment-shortformat 2.1
|
||||
// Project: https://github.com/researchgate/moment-shortformat#readme
|
||||
// Definitions by: whatasoda <https://github.com/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;
|
||||
}
|
||||
}
|
||||
20
types/moment-shortformat/moment-shortformat-tests.ts
Normal file
20
types/moment-shortformat/moment-shortformat-tests.ts
Normal file
@@ -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'
|
||||
23
types/moment-shortformat/tsconfig.json
Normal file
23
types/moment-shortformat/tsconfig.json
Normal 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-shortformat-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/moment-shortformat/tslint.json
Normal file
1
types/moment-shortformat/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user