3.0.0 • Published 1 year ago

s2hms v3.0.0

Weekly downloads
43
License
MIT
Repository
github
Last release
1 year ago

s2hms

npm example workflow example workflow

convert seconds to HMS (or) to hours, minutes, seconds explicitly.

Install

npm install s2hms

Usage

contains two types of modules :

  1. s2hms
  2. s2h, s2m, s2s

1) s2hms : converts seconds to 'hms' format.

takes two arguments : seconds (number) , options (object optional)

import { s2hms } from "s2hms";

s2hms(4342);
//  01:12:22

s2hms(1432);
//  00:23:52

s2hms(64567, { format: "short" });
//  17h:56m:07s

s2hms(432, { format: "long" });
//  07minutes:12seconds

s2hms(8573, { format: "long", separator: "__" });
//  02hours__22minutes__53seconds

options

keyvaltypedefault val
format'long', 'short', 'standardstring'standard'
separatorany string char ':' , '+' , '=' , '_' ,'-' , etc...string':'

example:

with separator: '/' and format: 'short'

s2hms(983, { format: "short", separator: "/" });
// => 16m/23s

2) ( s2h, s2m, s2s ) : converts seconds to hours, minutes, seconds explicitly.

takes two arguments : seconds (number) , options (object optional)

import { s2h, s2m, s2s } from "s2hms";

s2h(43434);
//  12.1

s2m(9832, { format: "short" });
//  163.9 m

s2m(98907, { format: "long" });
//  1648.5 minutes

s2s(9832, { format: "short" });
//  9832 s

options

keyvaltypedefault val
format'long', 'short', 'standard'string'standard'
fallbacktrue, falsebooleanfalse

when fallback is set to true, conversion auto downgrades to next unit if the resulting value is less than 1 (one),

examples:

without fallback

s2h(983, { format: "short" });
//  0.3 h

with fallback set to true

s2h(983, { format: "short", fallback: true });
//  16.4 m

without fallback

s2m(46, { format: "long" });
//  0.8 minute

with fallback set to true

s2m(46, { format: "long", fallback: true });
//  46 seconds

note: fallback can be used only when a format is specified , if no format is specified and fallback is set to true , it will throw an error, this is to prevent confusion of resulting value's unit type.

s2h(634, { fallback: true });
//   Error: option'fallback:true' can only be used when a format is specified

License

MIT

3.0.0

1 year ago

2.1.3

2 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago