Getting started
Niobe gives you small functions for writing, converting, parsing and formatting durations. Every duration is a plain number of milliseconds, so it works anywhere a number of milliseconds does: setTimeout, Date arithmetic, cache lifetimes, rate limits and so on.
The problem
How often do you write code like this?
ts
setTimeout(refresh, 1_000 * 60 * 2.5);1_000 * 60 * 2.5 takes a moment to read, and every project grows its own constants for it, named differently by each person who needs one.
The solution
With Niobe, the same duration says what it means:
ts
setTimeout(refresh, minutes(2) + seconds(30));Installation
sh
npm install niobesh
pnpm add niobesh
yarn add niobeNiobe has no runtime dependencies. It ships ESM and CommonJS builds, with types.
What's included
- Converting units:
weeks,days,hours,minutes,seconds,milliseconds,microsecondsandnanoseconds, each with.from()to convert back. - Constants:
MINUTE,HOUR,SECONDS_IN_MINUTEand friends. - Duration strings: parse
'1h 30m'withparseDuration. - Clock strings: read and write
'01:30:00'withclockToMsandmsToClock. - Parts: split a duration into units with
msToParts, and join them withpartsToMs.
The API reference lists every export.