Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ms

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ms - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

14

component.json
{
"name": "ms",
"repo": "guille/ms.js",
"version": "0.4.0",
"description": "ms parsing / formatting",
"keywords": ["ms", "parse", "format"],
"scripts": ["index.js"]
}
"keywords": [
"ms",
"parse",
"format"
],
"scripts": [
"index.js"
],
"license": "MIT"
}
0.5.0 / 2012-11-09
==================
* add short formatting as default and .long option
* add .license property to component.json
* add version to component.json
0.4.0 / 2012-10-22

@@ -3,0 +10,0 @@ ==================

@@ -14,3 +14,8 @@

*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} options
* @return {String|Number}

@@ -20,6 +25,9 @@ * @api public

module.exports = function(val){
module.exports = function(val, options){
options = options || {};
if ('string' == typeof val) return parse(val);
return format(val);
}
return options.long
? long(val)
: short(val);
};

@@ -66,10 +74,26 @@ /**

/**
* Format the given `ms`.
* Short format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api public
* @api private
*/
function format(ms) {
function short(ms) {
if (ms >= d) return Math.round(ms / d) + 'd';
if (ms >= h) return Math.round(ms / h) + 'h';
if (ms >= m) return Math.round(ms / m) + 'm';
if (ms >= s) return Math.round(ms / s) + 's';
return ms + 'ms';
}
/**
* Long format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function long(ms) {
if (ms == d) return Math.round(ms / d) + ' day';

@@ -76,0 +100,0 @@ if (ms > d) return Math.round(ms / d) + ' days';

{
"name": "ms"
, "version": "0.4.0"
, "version": "0.5.0"
, "description": "Tiny ms conversion utility"

@@ -5,0 +5,0 @@ , "main": "./index"

@@ -13,7 +13,13 @@ # ms.js: miliseconds conversion utility

```js
ms(60000) // "1 minute"
ms(2 * 60000) // "2 minutes"
ms(ms('10 hours')) // "10 hours"
ms(60000) // "1m"
ms(2 * 60000) // "2m"
ms(ms('10 hours')) // "10h"
```
```js
ms(60000, { long: true }) // "1 minute"
ms(2 * 60000, { long: true }) // "2 minutes"
ms(ms('10 hours', { long: true })) // "10 hours"
```
- Node/Browser compatible. Published as `ms` in NPM.

@@ -20,0 +26,0 @@ - If a number is supplied to `ms`, a string with a unit is returned.

@@ -57,30 +57,62 @@

describe('ms(number, { long: true })', function(){
it('should support milliseconds', function(){
expect(ms(500, { long: true })).to.be('500 ms');
})
it('should support seconds', function(){
expect(ms(1000, { long: true })).to.be('1 second');
expect(ms(10000, { long: true })).to.be('10 seconds');
})
it('should support minutes', function(){
expect(ms(60 * 1000, { long: true })).to.be('1 minute');
expect(ms(60 * 10000, { long: true })).to.be('10 minutes');
})
it('should support hours', function(){
expect(ms(60 * 60 * 1000, { long: true })).to.be('1 hour');
expect(ms(60 * 60 * 10000, { long: true })).to.be('10 hours');
})
it('should support days', function(){
expect(ms(24 * 60 * 60 * 1000, { long: true })).to.be('1 day');
expect(ms(24 * 60 * 60 * 10000, { long: true })).to.be('10 days');
})
it('should round', function(){
expect(ms(234234234, { long: true })).to.be('3 days');
})
})
// numbers
describe('ms(number)', function(){
it('should support milliseconds', function(){
expect(ms(500)).to.be('500 ms');
expect(ms(500)).to.be('500ms');
})
it('should support seconds', function(){
expect(ms(1000)).to.be('1 second');
expect(ms(10000)).to.be('10 seconds');
expect(ms(1000)).to.be('1s');
expect(ms(10000)).to.be('10s');
})
it('should support minutes', function(){
expect(ms(60 * 1000)).to.be('1 minute');
expect(ms(60 * 10000)).to.be('10 minutes');
expect(ms(60 * 1000)).to.be('1m');
expect(ms(60 * 10000)).to.be('10m');
})
it('should support hours', function(){
expect(ms(60 * 60 * 1000)).to.be('1 hour');
expect(ms(60 * 60 * 10000)).to.be('10 hours');
expect(ms(60 * 60 * 1000)).to.be('1h');
expect(ms(60 * 60 * 10000)).to.be('10h');
})
it('should support days', function(){
expect(ms(24 * 60 * 60 * 1000)).to.be('1 day');
expect(ms(24 * 60 * 60 * 10000)).to.be('10 days');
expect(ms(24 * 60 * 60 * 1000)).to.be('1d');
expect(ms(24 * 60 * 60 * 10000)).to.be('10d');
})
it('should round', function(){
expect(ms(234234234)).to.be('3 days');
expect(ms(234234234)).to.be('3d');
})
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc