DWS Packages
    Preparing search index...

    Module @dws-std/common - v1.3.1

    DWS Common logo

    🧰 DWS Common

    Small utilities you'll want everywhere, but don't belong to any specific domain.
    Instead of copy-pasting the same helpers across every project, @dws-std/common collects them in one place so you can just import and move on.

    bun add @dws-std/common
    

    Converts a human-readable time expression into a numeric value in the unit of your choice.
    Useful anywhere you need to define durations without sprinkling magic numbers — JWT expiry, TTLs, rate-limit windows, you name it.

    import { parseHumanTime } from '@dws-std/common';

    parseHumanTime('2 hours'); // 7200 (seconds by default)
    parseHumanTime('30 mins'); // 1800
    parseHumanTime('1 day'); // 86400
    parseHumanTime('2 weeks'); // 1209600
    parseHumanTime('1 year'); // 31557600

    Choose a different output unit with the second argument:

    parseHumanTime('1 hour', 'minutes'); // 60
    parseHumanTime('1 day', 'hours'); // 24
    parseHumanTime('1 second', 'ms'); // 1000

    Past and future offsets are also supported:

    parseHumanTime('30 mins ago'); // -1800
    parseHumanTime('+1 day'); // 86400
    parseHumanTime('-2 hours'); // -7200
    parseHumanTime('1 hour from now'); // 3600

    Supported units:

    Unit Accepted aliases
    Second s, sec, secs, second, seconds
    Minute m, min, mins, minute, minutes
    Hour h, hr, hrs, hour, hours
    Day d, day, days
    Week w, week, weeks
    Year y, yr, yrs, year, years

    Throws an Exception if the expression is invalid or the unit is unrecognised.

    Full docs: https://dominus-web-service.github.io/std/

    MIT - Feel free to use it.

    Classes

    TypedEventEmitter

    Type Aliases

    EventMap
    TimeUnit

    Variables

    PARSE_HUMAN_TIME_ERROR_KEYS

    Functions

    parseHumanTime