@types/timespan-parser
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

Installation

npm install --save @types/timespan-parser

Summary

This package contains type definitions for timespan-parser (https://github.com/gilly3/timespan-parser/).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/timespan-parser.

index.d.ts

declare namespace timespan {
    type Unit =
        | "msec"
        | "ms"
        | "seconds"
        | "second"
        | "sec"
        | "s"
        | "minutes"
        | "minute"
        | "min"
        | "m"
        | "hours"
        | "hour"
        | "hr"
        | "h"
        | "days"
        | "day"
        | "d"
        | "weeks"
        | "week"
        | "w"
        | "months"
        | "month"
        | "M"
        | "years"
        | "year"
        | "y";

    interface Options {
        /** The unit that value represents. Defaults to `"seconds"`. */
        unit?: Unit;
        /** Whether to abbreviate the unit labels in the resulting string. Defaults to `true`. */
        abbv?: boolean;
        /** Whether to set the first letter of each unit label to upper case in the resulting string. Defaults to `false`. */
        capitalize?: boolean;
        /** This string will be placed between each number and unit label in the resulting string. Defaults to `""` when `abbv` is `true`. Defaults to `" "` when `abbv` is `false`. */
        unitSep?: string;
        /** This string will be placed between each value in the resulting string. Defaults to `" "`. */
        valueSep?: string;
    }

    /**
     * Converts a timespan string into a number of `unit`s.
     * @param timespan The timespan string to be parsed.
     * @param unit The unit to use for the conversion. Defaults to `"seconds"`.
     * @returns The number of `unit`s represented by `timespan`.
     */
    function parse(timespan: string, unit?: Unit): number;

    /**
     * Converts a numeric value to a timespan string. The timespan string produced uses the shortest label available.
     * @param value The number of `unit`s to convert to a timespan string.
     * @param opts Options object
     */
    function getString(value: number, opts?: Options | Unit): string;
}

/** Returns a new `timespan` object with the defaults modified. */
declare function timespan(
    defaults?: timespan.Options | timespan.Unit,
): {
    parse: typeof timespan.parse;
    getString: typeof timespan.getString;
};

export = timespan;

Additional Details

  • Last updated: Tue, 07 Nov 2023 15:11:36 GMT
  • Dependencies: none

Credits

These definitions were written by OpportunityLiu.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/timespan-parser

Weekly Downloads

8

Version

1.2.3

License

MIT

Unpacked Size

6.85 kB

Total Files

5

Last publish

Collaborators

  • types