diff --git a/types/hh-mm-ss/hh-mm-ss-tests.ts b/types/hh-mm-ss/hh-mm-ss-tests.ts new file mode 100644 index 0000000000..b08aa6c7c0 --- /dev/null +++ b/types/hh-mm-ss/hh-mm-ss-tests.ts @@ -0,0 +1,13 @@ +import { fromMs, fromS, toMs, toS } from 'hh-mm-ss'; + +const ms = fromMs(60000); +const msWithFormat = fromMs(60000, 'mm:ss'); + +const s = fromS(3000); +const sWithFormat = fromS(3000, 'hh:mm:ss'); + +const ms2 = toMs('12:23:34'); +const msWithFormat2 = toMs('12:23:34', 'mm:ss'); + +const s2 = toS('12:23:34'); +const sWithFormat2 = toS('12:23:34', 'mm:ss'); diff --git a/types/hh-mm-ss/index.d.ts b/types/hh-mm-ss/index.d.ts new file mode 100644 index 0000000000..c9e0783ad8 --- /dev/null +++ b/types/hh-mm-ss/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for hh-mm-ss 1.2 +// Project: https://github.com/Goldob/hh-mm-ss#readme +// Definitions by: Thomas Cazade +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Convert given `hh:mm:ss` formatted string to miliseconds + * + * @param time String representation + * @param format Default input format. If present, it will be used to resolve + * ambiguities during interpretation. If not specified, `mm:ss` is implied. + * [See section below for supported format list](https://github.com/Goldob/hh-mm-ss#supported-time-formats) + */ +export function toMs(time: string, format?: string): string; + +/** + * Convert given `hh:mm:ss` formatted string to seconds + * + * @param time String representation + * @param format Default input format. If present, it will be used to resolve + * amiguities during interpretation. If not specified, `mm:ss` is implied. + * [See section below for supported format list](https://github.com/Goldob/hh-mm-ss#supported-time-formats) + */ +export function toS(time: string, format?: string): string; + +/** + * Generate formatted string from time in miliseconds + * + * @param ms Time in miliseconds + * @param format Default output format. If not specified, `mm:ss` is implied. + * [See section below for supported format list](https://github.com/Goldob/hh-mm-ss#supported-time-formats) + */ +export function fromMs(ms: number, format?: string): string; + +/** + * Generate formatted string from time in seconds + * + * @param s Time in seconds + * @param format Default output format. If not specified, `mm:ss` is implied. + * [See section below for supported format list](https://github.com/Goldob/hh-mm-ss#supported-time-formats) + */ +export function fromS(s: number, format?: string): string; diff --git a/types/hh-mm-ss/tsconfig.json b/types/hh-mm-ss/tsconfig.json new file mode 100644 index 0000000000..d7619f323d --- /dev/null +++ b/types/hh-mm-ss/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", + "hh-mm-ss-tests.ts" + ] +} diff --git a/types/hh-mm-ss/tslint.json b/types/hh-mm-ss/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hh-mm-ss/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }