Socket
Socket
Sign inDemoInstall

ms

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ms

Tiny ms conversion utility


Version published
Weekly downloads
186M
decreased by-16.98%
Maintainers
1
Install size
248 kB
Created
Weekly downloads
 

Package description

What is ms?

The 'ms' npm package is a simple utility library for parsing and formatting various time formats. It allows you to easily convert between different time units such as milliseconds, seconds, minutes, hours, and days. It is commonly used to work with durations and timeouts in a human-readable format.

What are ms's main functionalities?

Convert from milliseconds to human-readable format

This feature allows you to convert a duration in milliseconds to a string that represents the duration in a more human-readable format, such as '1m' for one minute.

"const ms = require('ms');
console.log(ms(60000)); // '1m'"

Convert from human-readable format to milliseconds

This feature enables you to convert a human-readable time format into its equivalent number of milliseconds. For example, '2 days' would be converted to 172800000 milliseconds.

"const ms = require('ms');
console.log(ms('2 days')); // 172800000"

Round trip conversion

This demonstrates a round trip conversion where a human-readable duration is first converted to milliseconds and then back to a human-readable format.

"const ms = require('ms');
const duration = ms('1 hour');
console.log(ms(duration)); // '1h'"

Other packages similar to ms

Readme

Source

ms.js

Ever find yourself doing math in your head or writing 1000 * 60 * 60 …? Don't want to add obstrusive Number prototype extensions to your reusable / distributable modules and projects?

ms is a tiny utility that you can leverage when your application needs to accept a number of miliseconds as a parameter.

If a number is supplied to ms, it returns it immediately (e.g: If a string that contains the number is supplied, it returns it immediately as a number (e.g: it returns 100 for '100').

However, if you pass a string with a number and a valid unit, hte number of equivalent ms is returned.

ms('1d')      // 86400000
ms('10h')     // 36000000
ms('2h')      // 7200000
ms('1m')      // 60000
ms('5ms')     // 5000
ms('100')     // '100'
ms(100)       // 100

How to use

Node

require('ms')

Browser

<script src="ms.js"></script>

Credits

(The MIT License)

Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Last updated on 21 Dec 2011

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc