An easy way to use readable timestrings in your code.
This library is written because of the problem with jsonwebtokens and cookies. I find it a lot easier to say 5d instead of calculating the amount of ms in 5 days. This library is also very useful for other things like timeouts and intervals.
- Convert timestrings to milliseconds
- Convert timestrings to seconds
- Convert timestrings to minutes
- Convert timestrings to hours
- Convert timestrings to days
- Works in ESM CJS and typescript
To install this library, you can use npm or yarn.
npm install timestringconverter
yarn add timestringconverter
important: you need to use d, h, m, s and ms to define the time. You can also use uppercase letters.
const timestringconverter = require('timestringconverter');
console.log(timestringconverter.toMilliseconds('5d')); // 432000000
console.log(timestringconverter.toSeconds('5d2h4m')); // 432144
console.log(timestringconverter.toMinutes('5d9h')); // 7209
console.log(timestringconverter.toHours('5d2H')); // 122
console.log(timestringconverter.toDays('2h500m10000ms')); // 4.57
Guidelines for contributing to the project. Include information on how to report issues, suggest improvements, or submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.