@coderosh/string-time
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

string-time

Convert time string into seconds, minutes, hour, array or object and vice versa.

NPM MIT CI PRs welcome! Typescript

Installation

Install via npm

npm install @coderosh/string-time

Or via yarn

yarn add @coderosh/string-time

Usage

import stringTime, { reverse } from '@coderosh/string-time'

stringTime

const time = stringTime('1:59:60')

time.array // [ 2, 0, 0 ]
time.string // 02:00:00
time.object // { hour: 2, minute: 0, second: 0 }
time.totalHours // 2
time.totalMinutes // 120
time.totalSeconds // 7200

stringTime('').string // 00:00:00
stringTime(':1:').string // 00:01:00
stringTime('1').string // 01:00:00
stringTime('::1').string // 00:00:01

reverse

reverse({ second: 7200 }) // 02:00:00
reverse({ hour: 2 }) // 02:00:00
reverse({ minute: 120 }) // 02:00:00
reverse({ hour: 2, minute: 1, second: 0 }) // 02:01:00
reverse([2, 0, 1]) // 02:00:01

Package Sidebar

Install

npm i @coderosh/string-time

Weekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

7.1 kB

Total Files

6

Last publish

Collaborators

  • coderosh