Registry / productivity / duration-format

duration-format

JSON →
library0.0.2jsnpmunverified

A lightweight JavaScript library for formatting durations (milliseconds) into human-readable strings using template patterns with placeholders for days, hours, minutes, seconds, and milliseconds. Version 0.0.2 is the latest and only release, with no active development. It differs from other duration formatters (e.g., moment.js duration, Intl.RelativeTimeFormat) by offering a simple, pattern-based syntax inspired by Ruby's String#% and does not depend on any external libraries. The library works in both Node.js and browser environments and supports zero-padding via number prefix in placeholders.

productivity
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Package only provides a CommonJS default export; ESM import works in bundlers but is not officially supported.

import df from 'duration-format'

The library exports a single function as module.exports.

const df = require('duration-format')

Not applicable since there is no .default export; this is not a valid pattern.

const df = require('duration-format').default

Formats a duration (in milliseconds) using templates with optional zero-padding placeholders.

const df = require('duration-format'); const S = 1000; const M = 60 * S; const H = 60 * M; const D = 24 * H; const duration = 2*D + 3*H + 45*M + 6*S + 78; console.log(df(duration, '#{D} Day #{H} : #{M} : #{S} . #{MS}')); // Output: 2 Day 3 : 45 : 6 . 78 console.log(df(duration, '#{4D} Day #{2H} : #{2M} : #{2S} . #{3MS}')); // Output: 0002 Day 03 : 45 : 06 . 078 console.log(df(duration, '#{2H} : #{2M} : #{2S}')); // Output: 51 : 45 : 06
Debug
Known footguns
gotchaPlaceholder numbers (e.g., #{4D}) are zero-padded to the specified width, but if the number of digits exceeds the width, the full number is shown; no truncation occurs.
gotchaThe library does not support locale-specific formatting or timezone handling; all calculations are based on raw milliseconds.
deprecatedThe package has not been updated since initial release; no active maintenance or support.
gotchaPlaceholder names must be capitalized exactly: D, H, M, S, MS. Lowercase or other variations will not be replaced.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
gptbot
3
amazonbot
3
bytedance
3
ahrefsbot
2
Resources