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

humanize-duration

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

humanize-duration - npm Package Compare versions

Comparing version 3.31.0 to 3.32.0

5

HISTORY.md

@@ -0,1 +1,6 @@

# 3.32.0 / 2024-03-29
- new: Amharic support (`am`)
- change: use `Object.assign` internally on newer runtimes, which should be slightly faster
# 3.31.0 / 2023-11-10

@@ -2,0 +7,0 @@

105

humanize-duration.js

@@ -26,3 +26,4 @@ // HumanizeDuration.js - https://git.io/j0HgmQ

/**
* @typedef {Record<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9", string>} DigitReplacements
* @internal
* @typedef {[string, string, string, string, string, string, string, string, string, string]} DigitReplacements
*/

@@ -65,2 +66,3 @@

/**
* @internal
* @typedef {Required<Options>} NormalizedOptions

@@ -70,2 +72,26 @@ */

(function () {
// Fallback for `Object.assign` if relevant.
var assign =
Object.assign ||
/** @param {...any} destination */
function (destination) {
var source;
for (var i = 1; i < arguments.length; i++) {
source = arguments[i];
for (var prop in source) {
if (has(source, prop)) {
destination[prop] = source[prop];
}
}
}
return destination;
};
// Fallback for `Array.isArray` if relevant.
var isArray =
Array.isArray ||
function (arg) {
return Object.prototype.toString.call(arg) === "[object Array]";
};
// This has to be defined separately because of a bug: we want to alias

@@ -103,3 +129,6 @@ // `gr` and `el` for backwards-compatiblity. In a breaking change, we can

/** @type {Record<string, Language>} */
/**
* @internal
* @type {Record<string, Language>}
*/
var LANGUAGES = {

@@ -131,2 +160,3 @@ af: language(

),
am: language("ዓመት", "ወር", "ሳምንት", "ቀን", "ሰዓት", "ደቂቃ", "ሰከንድ", "ሚሊሰከንድ"),
ar: assign(

@@ -1429,2 +1459,3 @@ language(

*
* @internal
* @param {Unit} y

@@ -1453,2 +1484,3 @@ * @param {Unit} mo

*
* @internal
* @param {number} c

@@ -1470,2 +1502,3 @@ * @returns {0 | 1 | 2}

*
* @internal
* @param {number} c

@@ -1490,2 +1523,3 @@ * @returns {0 | 1 | 2 | 3}

*
* @internal
* @param {number} c

@@ -1517,2 +1551,3 @@ * @returns {0 | 1 | 2 | 3}

*
* @internal
* @param {number} c

@@ -1537,2 +1572,3 @@ * @returns {0 | 1 | 2 | 3}

*
* @internal
* @param {number} c

@@ -1558,2 +1594,3 @@ * @returns {0 | 1 | 2}

*
* @internal
* @param {number} c

@@ -1566,23 +1603,9 @@ * @returns {boolean}

function assign(destination) {
var source;
for (var i = 1; i < arguments.length; i++) {
source = arguments[i];
for (var prop in source) {
if (has(source, prop)) {
destination[prop] = source[prop];
}
}
}
return destination;
}
// We need to make sure we support browsers that don't have
// `Array.isArray`, so we define a fallback here.
var isArray =
Array.isArray ||
function (arg) {
return Object.prototype.toString.call(arg) === "[object Array]";
};
/**
* @internal
* @template T
* @param {T} obj
* @param {keyof T} key
* @returns {boolean}
*/
function has(obj, key) {

@@ -1593,2 +1616,3 @@ return Object.prototype.hasOwnProperty.call(obj, key);

/**
* @internal
* @param {Pick<Required<Options>, "language" | "fallbacks" | "languages">} options

@@ -1623,2 +1647,3 @@ * @throws {Error} Throws an error if language is not found.

/**
* @internal
* @param {Piece} piece

@@ -1668,2 +1693,3 @@ * @param {Language} language

} else {
// @ts-ignore because `char` should always be 0-9 at this point.
formattedCount += digitReplacements[char];

@@ -1691,2 +1717,3 @@ }

/**
* @internal
* @typedef {Object} Piece

@@ -1698,2 +1725,3 @@ * @prop {UnitName} unitName

/**
* @internal
* @param {number} ms

@@ -1811,2 +1839,3 @@ * @param {Pick<Required<Options>, "units" | "unitMeasures" | "largest" | "round">} options

/**
* @internal
* @param {Piece[]} pieces

@@ -1865,4 +1894,11 @@ * @param {Pick<Required<Options>, "units" | "language" | "languages" | "fallbacks" | "delimiter" | "spacer" | "decimal" | "conjunction" | "maxDecimalPoints" | "serialComma" | "digitReplacements">} options

* Create a humanizer, which lets you change the default options.
*
* @param {Options} [passedOptions]
*/
function humanizer(passedOptions) {
/**
* @param {number} ms
* @param {Options} [humanizerOptions]
* @returns {string}
*/
var result = function humanizer(ms, humanizerOptions) {

@@ -1912,16 +1948,15 @@ // Make sure we have a positive number.

*/
var humanizeDuration = humanizer({});
humanizeDuration.getSupportedLanguages = function getSupportedLanguages() {
var result = [];
for (var language in LANGUAGES) {
if (has(LANGUAGES, language) && language !== "gr") {
result.push(language);
var humanizeDuration = assign(humanizer({}), {
getSupportedLanguages: function getSupportedLanguages() {
var result = [];
for (var language in LANGUAGES) {
if (has(LANGUAGES, language) && language !== "gr") {
result.push(language);
}
}
}
return result;
};
return result;
},
humanizer: humanizer
});
humanizeDuration.humanizer = humanizer;
// @ts-ignore

@@ -1928,0 +1963,0 @@ if (typeof define === "function" && define.amd) {

@@ -35,5 +35,6 @@ {

"Michal Karzel (https://github.com/Misioka)",
"Batmend Ganbaatar (https://github.com/theironbatka)"
"Batmend Ganbaatar (https://github.com/theironbatka)",
"Mikias Menjeta (https://github.com/OMikiasO)"
],
"version": "3.31.0",
"version": "3.32.0",
"description": "Convert millisecond durations to English and many other languages.",

@@ -50,8 +51,9 @@ "homepage": "https://github.com/EvanHahn/HumanizeDuration.js",

"devDependencies": {
"@types/node": "^20.9.0",
"csv-parse": "^5.5.2",
"eslint": "^8.53.0",
"@types/ms": "^0.7.34",
"@types/node": "^20.11.30",
"csv-parse": "^5.5.5",
"eslint": "^8.57.0",
"ms": "^2.1.3",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
"prettier": "^3.2.5",
"typescript": "^5.4.3"
},

@@ -58,0 +60,0 @@ "keywords": [

@@ -345,2 +345,3 @@ # Humanize Duration

| Albanian | `sq` |
| Amharic | `am` |
| Arabic | `ar` |

@@ -451,2 +452,3 @@ | Basque | `eu` |

- [Michal Karzel](https://github.com/Misioka) for improving Arabic support
- [Mikias Menjeta](https://github.com/OMikiasO) for Amharic support

@@ -453,0 +455,0 @@ Licensed under the permissive [Unlicense](https://unlicense.org/). Enjoy!

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