f4t
v1.1.0
Published
A package for formatting times.
Downloads
6
Readme
f4t
A package for formatting times.
Usage
w = weeks, d = days, h = hours, m = minutes, s = seconds, ms = milli seconds
const { decode, encode } = require('f4t');
console.log(decode('2w3d18h40m3s2ms')); // 153960003002
console.log(encode(1536003002)); // '2w3d18h40m3s2ms'
console.log(decode('abc')); // NaN
console.log(encode(-1000)); // NaN
console.log(decode('0ms')); // 0
console.log(encode(0)); // '0ms'
// encode(milliseconds, formatOption);
// The usage of time symbols is restricted by formatOption (The use of 'ms' cannot be restricted).
console.log(encode(1536003002, ['w'])); // '17d18h40m3s2ms'
console.log(encode(1536003002, ['w', 's'])); // '17d18h40m3002ms'