2.1.3 • Published 8 months ago

parse-duration v2.1.3

Weekly downloads
108,210
License
MIT
Repository
github
Last release
8 months ago

parse-duration Test

Convert a human readable duration to ms.

NPM

Usage

import parse from 'parse-duration'

// parse different time units
let ns = parse('1ns')       // => 1 / 1e6
let μs = parse('1μs')       // => 1 / 1000
let ms = parse('1ms')       // => 1
let s = parse('1s')         // => ms * 1000
let m = parse('1m')         // => s * 60
let h = parse('1h')         // => m * 60
let d = parse('1d')         // => h * 24
let w = parse('1w')         // => d * 7
let mo = parse('1mo')       // => y / 12
let y = parse('1y')         // => d * 365.25

// compound expressions
parse('1hr 20mins')         // => 1 * h + 20 * m
parse('1 hr 20 mins')       // => 1 * h + 20 * m

// youtube format
parse('1h20m0s')            // => 1 * h + 20 * m

// comma seperated numbers
parse('27,681 ns')          // => 27681 * ns

// noisy input
parse('duration: 1h:20min') // => 1 * h + 20 * m

// negatives
parse('-1hr 40mins')        // => -1 * h - 40 * m

// exponents
parse('2e3s')               // => 2000 * s

// custom output format
parse('1hr 20mins', 'm')    // => 80

// add units
parse.unit['μs'] = parse.unit.microsecond
parse('5μs')                // => 0.005

Locales

Switch the default en locale to another language (see /locale).

import es from 'parse-duration/locale/es.js'
import parse from 'parse-duration'

parse.unit = es

parse('1 hora 20 minutos', 'm') // 80

Safety

In sensitive APIs make sure input string is reasonably short (under 100 characters).

@apecommerce/ape-framework@ape-framework/serverchinjowwchinjownode-red-contrib-belimocloud-connector@mst-systemtechnik/node-red-contrib-belimocloudfeature-toggle-nodes2m-env-configtaskloft@xavo/climongodash-ttt@plasmo-corp/web-ext-deployfalls.djs@infinitebrahmanuniverse/nolb-parse-dap-clidata-access-platform-cligodspeed-nodeipfs-http-clientlinguist2use@everything-registry/sub-chunk-2410@mindgrep/corep2pchord2tancachetcachesystemic-expresssystemic-service-runnersys-watchertennu-tellwait4walletsucretempdb-clisutrosupportedvue-api-client@rsksmart/rif-marketplace-upload-service@rsksmart/rif-storage-pinningjaidbotjaidbot-desktopjikan4.jsipfs-demoipfs-http-serverjsreport-reportsjoshuaprojs-kubo-rpc-clientipfs-coreipfs-core-utilsipfs-cliipfs-core-skogardhttp-monitorhyperterm-base16influxdb-builderhogdchsk-code-push-clihere-spotgurkensalatlemongrasslifxshloopback-connector-influxloopback-connector-influxdatalt-coremath-to-imagelogentries-query-clikubo-rpc-clientkubo-rpc-client-esm-cjsmarkdown-middlewaremarkdown-middleware-rebuildmedusa-plugin-abandoned-cartmedusa-plugin-abandoned-cart-wine-beta@webinmove/kumbukumbu@worldofgeese/core@xmader/ipfs-core@xmader/ipfs-http-client@twitwi/slidev-addon-ultracharger@types/parse-duration@thanhvd/code-push-cli@tgx-media/core@vex-chat/libvex@vex-chat/spire@vividn/datum@uploadx/core@zeitgeistpm/web3.storage@tedcryptoorg/cosmos-signeramnaagent-api@zowedev/zztop@zulustation/web3.storagearnique-utils@chowdeck/codepush-cli@goldskycom/cli@goodware/mysql@godspeedsystems/core@godspeedsystems/test@chris.troutner/ipfs-cli@chris.troutner/ipfs-core@chris.troutner/ipfs-core-utils@chris.troutner/ipfs-http-client@chris.troutner/ipfs-http-server@graphql-mesh/serve-cli@gregros/autogit
1.1.1

11 months ago

1.1.2

9 months ago

2.1.2

9 months ago

2.1.1

9 months ago

2.0.2

9 months ago

2.1.3

8 months ago

2.1.0

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.1.0

2 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.5.0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.1

5 years ago

0.4.2

5 years ago

0.4.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

11 years ago

0.1.0

12 years ago