https://github.com/elonehoo/concise-ms
understandable milliseconds
https://github.com/elonehoo/concise-ms
milliseconds tyepscript
Last synced: 6 months ago
JSON representation
understandable milliseconds
- Host: GitHub
- URL: https://github.com/elonehoo/concise-ms
- Owner: elonehoo
- License: mit
- Created: 2022-06-14T05:55:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T03:11:09.000Z (over 1 year ago)
- Last Synced: 2024-04-17T06:53:32.347Z (over 1 year ago)
- Topics: milliseconds, tyepscript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@elonehoo/concise-ms
- Size: 1.32 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
![]()
concise-ms
Convert milliseconds to string: `1337000000` ➡️ `15d 11h 23m 20s`## install
```bash
# npm
npm install @elonehoo/concise-ms
#yarn
yarn add @elonehoo/concise-ms
#pnpm
pnpm install @elonehoo/concise-ms
```## usage
```typescript
import { conciseMilliseconds } from '@elonehoo/concise-ms'conciseMilliseconds(1337000000) // => '15d 11h 23m 20s'
conciseMilliseconds(1337)// => '1.3s'
conciseMilliseconds(133)// => '133ms'
// `compact` option
conciseMilliseconds(1337, { compact: true })// => '1s'// `verbose` option
conciseMilliseconds(1335669000, { verbose: true })// => '15 days 11 hours 1 minute 9 seconds'// `colonNotation` option
conciseMilliseconds(95500, { colonNotation: true })// => '1:35.5'// `formatSubMilliseconds` option
conciseMilliseconds(100.400080, { formatSubMilliseconds: true })// => '100ms 400µs 80ns'// Can be useful for time durations
conciseMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))// => '35m'
```