EvanHahn / HumanizeDuration.js

361000 becomes "6 minutes, 1 second"
https://evanhahn.github.io/HumanizeDuration.js/
The Unlicense
1.65k stars 175 forks source link

[Feature Request] padding 0 to align result #206

Closed lqzhgood closed 2 years ago

lqzhgood commented 2 years ago

can add options to padding 0 to align result ?

like this

console.log(humanizeDuration(3884 * 1000, {padding:'0'} ));
console.log(humanizeDuration(5941 * 1000, {padding:'0'}));

//1 hour, 04 minutes, 44 seconds
//1 hour, 39 minutes, 01 seconds
lqzhgood commented 2 years ago

if any one have same feature, use this

  timeHumanize(s) {
            const DELIMITER = ' ';
            const str = humanizeDuration(s * 1000, { delimiter: DELIMITER });

            const reg = new RegExp(`(?<=[hour|minutes|seconds]${DELIMITER})(\\d{1})(?=${DELIMITER})`, 'g');
            return str.replace(reg, t => t.padStart(2, '0'));
        },
EvanHahn commented 2 years ago

This library is actively maintained but no new features will be added. Sorry!