From 0d448d3e5d37ef4c9f3be33303c7f2ff58dd59c3 Mon Sep 17 00:00:00 2001 From: Rico Sandyca Novenza Date: Tue, 3 Mar 2020 02:04:49 +0700 Subject: [PATCH] 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 --- types/human-date/human-date-tests.ts | 29 +++++++++++++++++ types/human-date/index.d.ts | 47 ++++++++++++++++++++++++++++ types/human-date/tsconfig.json | 23 ++++++++++++++ types/human-date/tslint.json | 3 ++ 4 files changed, 102 insertions(+) create mode 100644 types/human-date/human-date-tests.ts create mode 100644 types/human-date/index.d.ts create mode 100644 types/human-date/tsconfig.json create mode 100644 types/human-date/tslint.json diff --git a/types/human-date/human-date-tests.ts b/types/human-date/human-date-tests.ts new file mode 100644 index 0000000000..8899ba59d0 --- /dev/null +++ b/types/human-date/human-date-tests.ts @@ -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(); diff --git a/types/human-date/index.d.ts b/types/human-date/index.d.ts new file mode 100644 index 0000000000..de0abdd656 --- /dev/null +++ b/types/human-date/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for human-date 1.4 +// Project: https://github.com/montanaflynn/human-date +// Definitions by: Rico Sandyca Novenza +// 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; diff --git a/types/human-date/tsconfig.json b/types/human-date/tsconfig.json new file mode 100644 index 0000000000..f50b1771ad --- /dev/null +++ b/types/human-date/tsconfig.json @@ -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" + ] +} diff --git a/types/human-date/tslint.json b/types/human-date/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/human-date/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}