Atomic classes for working with Normal Play Time (NPT) time codes from RFC 2326.
$ npm install npt-timecode
const { Timecode } = require('npt-timecode')
const timecode = Timecode.from('00:00:30.456-00:01:00.789')
console.log(timecode)
// Timecode (00:00:30.456-00:01:00.789) {
// start: Time (00:00:30.456) { value: 30.456 },
// stop: Time (00:01:00.789) { value: 60.789 }
// }
A container for Normal Play Time (NPT) timecodes that support ranges.
Creates a Timecode
instance from input.
Timecode.from({ start: 0, stop: 30.5 }) // in seconds
Timecode.from({ start: 'now' })
Timecode.from({ start: '00:05:32.5', stop: '00:06:00' })
Timecode.from('now-')
Timecode.from('00:05:32.5-00:06:00')
Timecode.from('00:05:00', '00:06:00')
A Time
instance that represents the start value of a timecode range.
If a range is not give, then it is the timecode value.
A Time
instance that represents the stop value of a timecode range.
This time value may not be set if the timecode is not a range.
Set the start and optional stop time values for this range.
timecode.set(30, 60) // 00:00:30-00:01:00
Reset the timecode state.
A container for a NPT integer time value represented in seconds.
A constant to represent "now" in a NPT scheme.
Creates a Time
instance from input.
const time = Time.from(305.5) // 5 minutes, 5 seconds, and half a second
// or
const time = Time.from('5:5.5')
// or
const time = Time.from('00:05:5.5')
// or
const time = Time.from({ minutes: 5, seconds: 5.5 })
Creates a "now" Time
instance.
const now = Time.now()
The integer value of the Time
instance.
true
if the time value is the "now" constant.
true
if the time value is valid. Meaning the time value is a valid
finite integer.
Computed total number of hours this Time
instance represents.
Computed total number of minutes this Time
instance represents.
Computed total number of seconds this Time
instance represents.
Computed total number of milliseconds this Time
instance represents.
Computed number of hours this Time
instance represents.
Computed number of minutes this Time
instance represents.
Computed number of seconds this Time
instance represents.
Computed number of milliseconds this Time
instance represents.
An alias for time.milliseconds
.
Set the time value for this instance.
Resets the value of this Time
instance to Number.NaN
.
Converts this Time
instance to an optionally formatted string.
time.toString('hh:mm::ss') // default format, padded time
time.toString('hh') // padded hours
time.toString('mm') // padded minutes
time.toString('ss') // padded seconds
time.toString('H') // total hours, not padded
time.toString('M') // total minutes, not padded
time.toString('S') // total seconds, not padded
Parse a NPT time string into milliseconds. This function does not parse range values.
MIT