parse-xsd-duration

Parse XSD durations to seconds (by default) or to object
Installation
$ npm install parse-xsd-duration
This package has zero dependencies and is provided in UMD format so you can easily use it in the browser.
Usage
import pxd from 'parse-xsd-duration'
pxd('PT2M10S')
pxd('P2Y6M5DT12H35M30S')
pxd('P1Y2M3DT5H20M30.123S')
pxd('PT2M10S', true)
pxd('P2Y6M5DT12H35M30S', true)
pxd('P1Y2M3DT5H20M30.123S', true)
API
parseXsdDuration(xsdDuration: string, toObject: boolean): number | object | null
- Converts an XSD duration string to seconds by default or to object with parameter
toObject
= true
.
- If the string is not a valid XSD duration, it will return
null
.
- If the input is not a string, it will throw a
TypeError
.
License
MIT © Mick Dekkers