Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/denolib/ms
Tiny milisecond conversion utility. Ported from https://npmjs.com/ms
https://github.com/denolib/ms
Last synced: 3 months ago
JSON representation
Tiny milisecond conversion utility. Ported from https://npmjs.com/ms
- Host: GitHub
- URL: https://github.com/denolib/ms
- Owner: denolib
- License: mit
- Created: 2018-12-20T00:22:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-15T17:34:13.000Z (about 4 years ago)
- Last Synced: 2024-06-21T18:10:12.233Z (5 months ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 17
- Watchers: 9
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deno - ms - 轻松地将各种时间格式转换为毫秒。 (Uncategorized / Uncategorized)
- awesome-deno-cn - @denolib/ms
- awesome-deno - ms - easily convert various time formats to milliseconds. (Libraries)
- awesome-deno - ms - Easily convert various time formats to milliseconds.![GitHub stars](https://img.shields.io/github/stars/denolib/ms?style=plastic) (Modules / Online Playgrounds)
- awesome-deno - ms - Easily convert various time formats to milliseconds. (Modules / Utils)
README
# `ms`
[![Build Status](https://travis-ci.org/denolib/ms.svg?branch=master)](https://travis-ci.org/denolib/ms)Use this package to easily convert various time formats to milliseconds.
It is ported from [https://github.com/zeit/ms](https://github.com/zeit/ms) to work with [Deno](https://deno.land). Ported mainly for use in porting `debug`.## Examples
```js
import { ms } from "https://raw.githubusercontent.com/denolib/ms/master/ms.ts";ms('2 days') // 172800000
ms('1d') // 86400000
ms('10h') // 36000000
ms('2.5 hrs') // 9000000
ms('2h') // 7200000
ms('1m') // 60000
ms('5s') // 5000
ms('1y') // 31557600000
ms('100') // 100
ms('-3 days') // -259200000
ms('-1h') // -3600000
ms('-200') // -200
```### Convert from Milliseconds
```js
ms(60000) // "1m"
ms(2 * 60000) // "2m"
ms(-3 * 60000) // "-3m"
ms(ms('10 hours')) // "10h"
```### Time Format Written-Out
```js
ms(60000, { long: true }) // "1 minute"
ms(2 * 60000, { long: true }) // "2 minutes"
ms(-3 * 60000, { long: true }) // "-3 minutes"
ms(ms('10 hours'), { long: true }) // "10 hours"
```