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

pretty-ms

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-ms - npm Package Compare versions

Comparing version 6.0.1 to 7.0.0

40

index.js

@@ -6,2 +6,4 @@ 'use strict';

const SECOND_ROUNDING_EPSILON = 0.0000001;
module.exports = (milliseconds, options = {}) => {

@@ -26,2 +28,8 @@ if (!Number.isFinite(milliseconds)) {

const floorDecimals = (value, decimalDigits) => {
const flooredInterimValue = Math.floor((value * (10 ** decimalDigits)) + SECOND_ROUNDING_EPSILON);
const flooredValue = Math.round(flooredInterimValue) / (10 ** decimalDigits);
return flooredValue.toFixed(decimalDigits);
};
const add = (value, long, short, valueString) => {

@@ -49,28 +57,2 @@ if ((result.length === 0 || !options.colonNotation) && value === 0 && !(options.colonNotation && short === 'm')) {

const secondsDecimalDigits =
typeof options.secondsDecimalDigits === 'number' ?
options.secondsDecimalDigits :
1;
if (secondsDecimalDigits < 1) {
const difference = 1000 - (milliseconds % 1000);
if (difference < 500) {
milliseconds += difference;
}
}
// Round up milliseconds for values lager than 1 minute - 50ms since these
// always need to be round up. This fixes issues when rounding seconds
// independently of minutes later on.
if (
milliseconds >= (1000 * 60) - 50 &&
!options.separateMilliseconds &&
!options.formatSubMilliseconds
) {
const difference = 60 - (milliseconds % 60);
if (difference <= 50) {
milliseconds += difference;
}
}
const parsed = parseMilliseconds(milliseconds);

@@ -113,3 +95,3 @@

add(
parseFloat(millisecondsString, 10),
Number.parseFloat(millisecondsString, 10),
'millisecond',

@@ -126,7 +108,7 @@ 'ms',

1;
const secondsFixed = seconds.toFixed(secondsDecimalDigits);
const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
const secondsString = options.keepDecimalsOnWholeSeconds ?
secondsFixed :
secondsFixed.replace(/\.0+$/, '');
add(parseFloat(secondsString, 10), 'second', 's', secondsString);
add(Number.parseFloat(secondsString, 10), 'second', 's', secondsString);
}

@@ -133,0 +115,0 @@

{
"name": "pretty-ms",
"version": "6.0.1",
"version": "7.0.0",
"description": "Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`",

@@ -11,3 +11,3 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},

@@ -48,4 +48,4 @@ "engines": {

"tsd": "^0.11.0",
"xo": "^0.25.3"
"xo": "^0.30.0"
}
}

@@ -1,2 +0,2 @@

# pretty-ms [![Build Status](https://travis-ci.org/sindresorhus/pretty-ms.svg?branch=master)](https://travis-ci.org/sindresorhus/pretty-ms)
# pretty-ms [![Build Status](https://travis-ci.com/sindresorhus/pretty-ms.svg?branch=master)](https://travis-ci.com/sindresorhus/pretty-ms)

@@ -74,3 +74,3 @@ > Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`

Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time).

@@ -77,0 +77,0 @@ ##### keepDecimalsOnWholeSeconds

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