Add @types/human-date (#42736)

* Add @types/human-date

* Change tests filename

* Delete human-date.ts

* Update human-date-tests.ts

* Update index.d.ts

* Update index.d.ts

* Add files via upload

* Add files via upload

* Add files via upload
This commit is contained in:
Rico Sandyca Novenza 2020-03-03 02:04:49 +07:00 committed by GitHub
parent 39ac1fd3e7
commit 0d448d3e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import hdate = require('human-date');
// .prertyPrint method
hdate.prettyPrint('8-16-1987');
hdate.prettyPrint(new Date('8-16-1987'));
hdate.prettyPrint(-6400);
hdate.prettyPrint(new Date(1416448704578), { showTime: true });
// .relativeTime method
hdate.relativeTime(4);
hdate.relativeTime(4, {futureSuffix: "in the future"});
hdate.relativeTime("8-16-1987");
hdate.relativeTime(new Date("8-16-1987"));
hdate.relativeTime(new Date("8-16-1987"), { returnObject: true });
hdate.relativeTime(new Date("8-16-1987")).length;
hdate.relativeTime(new Date("8-16-1987"), { returnObject: true }).seconds;
hdate.relativeTime(75, { allUnits: true });
// .monthName method
hdate.monthName(8);
hdate.monthName("8-16-1987");
hdate.monthName(new Date("8-16-1987"));
// .toUTC method
hdate.toUTC(1000000000000);
hdate.toUTC(1000000000000).getFullYear();
hdate.toUTC("8-16-1987");
hdate.toUTC(new Date("8-16-1987"));
hdate.toUTC(new Date("8-16-1987")).toISOString();

47
types/human-date/index.d.ts vendored Normal file
View File

@ -0,0 +1,47 @@
// Type definitions for human-date 1.4
// Project: https://github.com/montanaflynn/human-date
// Definitions by: Rico Sandyca Novenza <https://github.com/ricosandyca>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface PrettyPrintOptions {
showTime?: boolean;
}
export interface RelativeTimeOptions {
futureSuffix?: string;
pastSuffix?: string;
presentText?: string;
returnObject?: boolean;
allUnits?: boolean;
}
export interface RelativeTimeReturns {
seconds: number;
hours: number;
days: number;
years: number;
past: boolean;
}
// prettyPrint
export function prettyPrint(
arg: string | Date | number,
options?: PrettyPrintOptions
): string;
// relativeTime
export function relativeTime(
arg: string | Date | number,
options?: RelativeTimeOptions & { returnObject?: false }
): string;
export function relativeTime(
arg: string | Date | number,
options: RelativeTimeOptions & { returnObject: true }
): RelativeTimeReturns;
// monthName
export function monthName(arg: string | Date | number): string;
// toUTC
export function toUTC(arg: string | Date | number): Date;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"human-date-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}