Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyfill Number.isFinite() to support PhantomJS #1575

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ function deepMergeProperty(base, extras) {
return mergedProperty;
}

const numberIsFinite = Number.isFinite || function(value) {
return typeof value === 'number' && isFinite(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos where is the isFinite() function from? You may need to import it from somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFinite() is a global function provided by JavaScript since ES3, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite

};

/**
* Adds a property __rank to array elements of type object {}
* If an inner element already has the __rank property it is not altered
Expand All @@ -461,7 +465,7 @@ function deepMergeProperty(base, extras) {
* @return rankedArray The original array with newly ranked elements
*/
function rankArrayElements(array, rank) {
if (!Array.isArray(array) || !Number.isFinite(rank))
if (!Array.isArray(array) || !numberIsFinite(rank))
return array;

array.forEach(function(el) {
Expand Down