2018-07-25 23:45:29 +08:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
|
|
|
|
if (!Object.entries) {
|
2018-11-28 07:03:54 +08:00
|
|
|
Object.entries = function(obj) {
|
|
|
|
var ownProps = Object.keys(obj),
|
|
|
|
i = ownProps.length,
|
|
|
|
resArray = new Array(i); // preallocate the Array
|
|
|
|
while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];
|
2018-07-25 23:45:29 +08:00
|
|
|
|
|
|
|
return resArray;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-28 07:07:05 +08:00
|
|
|
// adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
|
|
|
|
// missing in ie only
|
|
|
|
if (!Object.values) {
|
|
|
|
Object.values = function(obj) {
|
|
|
|
var ownProps = Object.keys(obj),
|
|
|
|
i = ownProps.length,
|
|
|
|
resArray = new Array(i); // preallocate the Array
|
|
|
|
while (i--) resArray[i] = obj[ownProps[i]];
|
|
|
|
|
|
|
|
return resArray;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:45:29 +08:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
2018-11-28 07:03:54 +08:00
|
|
|
if (typeof Object.assign !== "function") {
|
2018-07-25 23:45:29 +08:00
|
|
|
// Must be writable: true, enumerable: false, configurable: true
|
|
|
|
Object.defineProperty(Object, "assign", {
|
2018-11-28 07:03:54 +08:00
|
|
|
value: function assign(target) {
|
|
|
|
// .length of function is 2
|
|
|
|
"use strict";
|
|
|
|
if (target == null) {
|
|
|
|
// TypeError if undefined or null
|
|
|
|
throw new TypeError("Cannot convert undefined or null to object");
|
2018-07-25 23:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var to = Object(target);
|
|
|
|
|
|
|
|
for (var index = 1; index < arguments.length; index++) {
|
|
|
|
var nextSource = arguments[index];
|
|
|
|
|
2018-11-28 07:03:54 +08:00
|
|
|
if (nextSource != null) {
|
|
|
|
// Skip over if undefined or null
|
2018-07-25 23:45:29 +08:00
|
|
|
for (var nextKey in nextSource) {
|
|
|
|
// Avoid bugs when hasOwnProperty is shadowed
|
|
|
|
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
|
|
to[nextKey] = nextSource[nextKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return to;
|
|
|
|
},
|
|
|
|
writable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
}
|
2018-10-26 20:45:29 +08:00
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Polyfill
|
2018-10-26 20:54:03 +08:00
|
|
|
/* eslint-disable */
|
2018-10-26 20:45:29 +08:00
|
|
|
if (!Array.prototype.includes) {
|
2018-11-28 07:03:54 +08:00
|
|
|
Object.defineProperty(Array.prototype, "includes", {
|
2018-10-26 20:45:29 +08:00
|
|
|
value: function(searchElement, fromIndex) {
|
|
|
|
if (this == null) {
|
|
|
|
throw new TypeError('"this" is null or not defined');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. Let O be ? ToObject(this value).
|
|
|
|
var o = Object(this);
|
|
|
|
|
|
|
|
// 2. Let len be ? ToLength(? Get(O, "length")).
|
|
|
|
var len = o.length >>> 0;
|
|
|
|
|
|
|
|
// 3. If len is 0, return false.
|
|
|
|
if (len === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. Let n be ? ToInteger(fromIndex).
|
|
|
|
// (If fromIndex is undefined, this step produces the value 0.)
|
|
|
|
var n = fromIndex | 0;
|
|
|
|
|
|
|
|
// 5. If n ≥ 0, then
|
|
|
|
// a. Let k be n.
|
|
|
|
// 6. Else n < 0,
|
|
|
|
// a. Let k be len + n.
|
|
|
|
// b. If k < 0, let k be 0.
|
|
|
|
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
|
|
|
|
|
|
|
function sameValueZero(x, y) {
|
2018-11-28 07:03:54 +08:00
|
|
|
return (
|
|
|
|
x === y ||
|
|
|
|
(typeof x === "number" &&
|
|
|
|
typeof y === "number" &&
|
|
|
|
isNaN(x) &&
|
|
|
|
isNaN(y))
|
|
|
|
);
|
2018-10-26 20:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 7. Repeat, while k < len
|
|
|
|
while (k < len) {
|
|
|
|
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
|
|
|
// b. If SameValueZero(searchElement, elementK) is true, return true.
|
|
|
|
if (sameValueZero(o[k], searchElement)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-19 18:46:26 +08:00
|
|
|
// c. Increase k by 1.
|
2018-10-26 20:45:29 +08:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8. Return false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2018-10-26 20:54:03 +08:00
|
|
|
}
|
2018-10-27 06:10:03 +08:00
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
|
|
|
|
if (!String.prototype.includes) {
|
2018-11-28 07:03:54 +08:00
|
|
|
Object.defineProperty(String.prototype, "includes", {
|
2018-10-27 06:10:03 +08:00
|
|
|
value: function(search, start) {
|
2018-11-28 07:03:54 +08:00
|
|
|
if (typeof start !== "number") {
|
|
|
|
start = 0;
|
2018-10-27 06:10:03 +08:00
|
|
|
}
|
2018-11-19 18:46:26 +08:00
|
|
|
|
2018-10-27 06:10:03 +08:00
|
|
|
if (start + search.length > this.length) {
|
2018-11-28 07:03:54 +08:00
|
|
|
return false;
|
2018-10-27 06:10:03 +08:00
|
|
|
} else {
|
2018-11-28 07:03:54 +08:00
|
|
|
return this.indexOf(search, start) !== -1;
|
2018-10-27 06:10:03 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-28 07:03:54 +08:00
|
|
|
});
|
2018-10-27 06:10:03 +08:00
|
|
|
}
|
2018-11-19 18:46:26 +08:00
|
|
|
|
|
|
|
// https://tc39.github.io/ecma262/#sec-array.prototype.find
|
|
|
|
if (!Array.prototype.find) {
|
2018-11-28 07:03:54 +08:00
|
|
|
Object.defineProperty(Array.prototype, "find", {
|
2018-11-19 18:46:26 +08:00
|
|
|
value: function(predicate) {
|
2018-11-28 07:03:54 +08:00
|
|
|
// 1. Let O be ? ToObject(this value).
|
2018-11-19 18:46:26 +08:00
|
|
|
if (this == null) {
|
|
|
|
throw new TypeError('"this" is null or not defined');
|
|
|
|
}
|
|
|
|
|
|
|
|
var o = Object(this);
|
|
|
|
|
|
|
|
// 2. Let len be ? ToLength(? Get(O, "length")).
|
|
|
|
var len = o.length >>> 0;
|
|
|
|
|
|
|
|
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
2018-11-28 07:03:54 +08:00
|
|
|
if (typeof predicate !== "function") {
|
|
|
|
throw new TypeError("predicate must be a function");
|
2018-11-19 18:46:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
|
|
var thisArg = arguments[1];
|
|
|
|
|
|
|
|
// 5. Let k be 0.
|
|
|
|
var k = 0;
|
|
|
|
|
|
|
|
// 6. Repeat, while k < len
|
|
|
|
while (k < len) {
|
|
|
|
// a. Let Pk be ! ToString(k).
|
|
|
|
// b. Let kValue be ? Get(O, Pk).
|
|
|
|
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
|
|
|
// d. If testResult is true, return kValue.
|
|
|
|
var kValue = o[k];
|
|
|
|
if (predicate.call(thisArg, kValue, k, o)) {
|
|
|
|
return kValue;
|
|
|
|
}
|
|
|
|
// e. Increase k by 1.
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 7. Return undefined.
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
configurable: true,
|
|
|
|
writable: true
|
|
|
|
});
|
|
|
|
}
|
2019-01-04 01:03:01 +08:00
|
|
|
|
2019-04-29 22:58:17 +08:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags#Polyfill
|
|
|
|
if (RegExp.prototype.flags === undefined) {
|
|
|
|
Object.defineProperty(RegExp.prototype, "flags", {
|
|
|
|
configurable: true,
|
|
|
|
get: function() {
|
|
|
|
return this.toString().match(/[gimsuy]*$/)[0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-26 20:54:03 +08:00
|
|
|
/* eslint-enable */
|