DWS Packages
    Preparing search index...

    Module @dws-std/common - v1.1.0

    🧰 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 number of seconds.
    Useful anywhere you need to define durations without sprinkling magic numbers - JWT expiry, TTLs, rate-limit windows, you name it.

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

    parseHumanTimeToSeconds('2 hours'); // 7200
    parseHumanTimeToSeconds('30 mins'); // 1800
    parseHumanTimeToSeconds('1 day'); // 86400
    parseHumanTimeToSeconds('2 weeks'); // 1209600
    parseHumanTimeToSeconds('1 year'); // 31557600

    Past and future offsets are also supported:

    parseHumanTimeToSeconds('30 mins ago'); // -1800
    parseHumanTimeToSeconds('+1 day'); // 86400
    parseHumanTimeToSeconds('-2 hours'); // -7200
    parseHumanTimeToSeconds('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: Dominus-Web-Service.github.io/packages

    MIT - Feel free to use it.

    Variables

    PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS

    Functions

    parseHumanTimeToSeconds