1.1.13 • Published 2 years ago
@thatbadname/time-string-converter v1.1.13
Time-String-to-Seconds
A very simple light-weight package that can do a few simple functions on time strings\
Usage
Time strings should be formatted like <number><length>
. being the time (eg: 7) and being the length (eg: years). If no valid input is provided (eg: 26lmao
) it will ignore it and return 0
. Something like 1m 17lmao
would return 60
Time Phrase | Valid Variations |
---|---|
Seconds | s , sec , secs , second , seconds |
Minutes | m , min , mins , minute , minutes |
Hours | h , hour , hours |
Days | d , day , days |
Weeks | w , wk , week , weeks |
Months | mo , month , months |
Years | y , yr , year , years |
Installation
In your terminal run:
npm i @thatbadname/time-string-converter
and your done!
Code Examples
Converting to seconds
const convert = require('time-string-converter')
console.log(convert.convertStringToSeconds('1m'))
// Output: 60
Convert seconds to time string
const convert = require('time-string-converter')
console.log(convert.convertSecondsToTimeObject(61))
/* Output: {
years: 0,
months: 0,
weeks: 0,
days: 0,
hours: 0,
minutes: 1,
seconds: 1
}
*/
Convert seconds to formatted string
const convert = require('time-string-converter')
console.log(convert.reformatTimeString(61))
// Output: 1minute 1second
1.1.12
2 years ago
1.1.13
2 years ago
1.1.11
2 years ago
1.1.10
2 years ago
1.1.9
2 years ago
1.1.8
2 years ago
1.1.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago