Skip to content

Commit

Permalink
Use Object.assign where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Mar 29, 2024
1 parent a5622d2 commit 5ef5c05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- new: Amharic support (`am`)
- change: use `Object.assign` internally on newer runtimes, which should be slightly faster

# 3.31.0 / 2023-11-10

Expand Down
52 changes: 24 additions & 28 deletions humanize-duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
*/

(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
// `gr` and `el` for backwards-compatiblity. In a breaking change, we can
// remove `gr` entirely.
Expand Down Expand Up @@ -1564,34 +1588,6 @@
return c % 10 === 1 && c % 100 !== 11;
}

/**
* `Object.assign` for legacy environments. Difficult to make type-check.
*
* @internal
* @param {...any} destination
*/
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)) {
// @ts-ignore
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
Expand Down

0 comments on commit 5ef5c05

Please sign in to comment.