├── .prettierrc ├── element.polyfill.js ├── number.polyfill.js ├── uint-8-array.polyfill.js ├── function.polyfill.js ├── LICENSE ├── date.polyfill.js ├── math.polyfill.js ├── int-8-array.polyfill.js ├── window.polyfill.js ├── README.md ├── string.polyfill.js └── array.polyfill.js /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /element.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * Element. 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support ? ? ? ? ? ? 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | -------------------------------------------------------------------------------- /number.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * Number.isInteger() 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support 34 16 (No) 21 9 12 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | if (!Number.isInteger) { 12 | Number.isInteger = function (value) { 13 | return ( 14 | typeof value === 'number' && 15 | isFinite(value) && 16 | Math.floor(value) === value 17 | ); 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /uint-8-array.polyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Uint8Array.prototype.at() 3 | * version 0.0.0 4 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 5 | * Basic support No No No No No No 6 | * ------------------------------------------------------------------------------- 7 | */ 8 | if (!Uint8Array.prototype.at) { 9 | Object.defineProperty(Uint8Array.prototype, "at", 10 | { 11 | value: function (n) { 12 | // ToInteger() abstract op 13 | n = Math.trunc(n) || 0; 14 | // Allow negative indexing from the end 15 | if (n < 0) n += this.length; 16 | // OOB access is guaranteed to return undefined 17 | if (n < 0 || n >= this.length) return undefined; 18 | // Otherwise, this is just normal property access 19 | return this[n]; 20 | }, 21 | writable: true, 22 | enumerable: false, 23 | configurable: true 24 | }); 25 | } -------------------------------------------------------------------------------- /function.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * Function.prototype.displayName 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support No 13 No No No No 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | 12 | /** 13 | * Function.prototype.name 14 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 15 | * Basic support 15 1 No 10.5 6 14 16 | * ------------------------------------------------------------------------ 17 | */ 18 | if (Function.prototype.name !== "") { 19 | var rx = /function\ ([\w$]+)\(/; 20 | Object.defineProperty(Function.prototype, "name", { 21 | get: function () { 22 | var match = rx.exec(this + ""); 23 | return match && match.length === 2 ? match[1] : ""; 24 | }, 25 | configurable: true, 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Behnam Mohammadi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /date.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * Date.prototype.toISOString() 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support 3 1 9 10.5 5 12 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | if (!Date.prototype.toISOString) { 12 | Object.defineProperty(Date.prototype, 'toISOString', { 13 | configurable: true, 14 | writable: true, 15 | value: function () { 16 | function pad(number) { 17 | if (number < 10) { 18 | return '0' + number; 19 | } 20 | return number; 21 | } 22 | 23 | return ( 24 | this.getUTCFullYear() + 25 | '-' + 26 | pad(this.getUTCMonth() + 1) + 27 | '-' + 28 | pad(this.getUTCDate()) + 29 | 'T' + 30 | pad(this.getUTCHours()) + 31 | ':' + 32 | pad(this.getUTCMinutes()) + 33 | ':' + 34 | pad(this.getUTCSeconds()) + 35 | '.' + 36 | (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 37 | 'Z' 38 | ); 39 | }, 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /math.polyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Math.trunc() 3 | * version 0.0.0 4 | * Browser Compatibility: 5 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc#browser_compatibility 6 | */ 7 | if (!Math.trunc) { 8 | Math.trunc = function (n) { 9 | return n < 0 ? Math.ceil(n) : Math.floor(n); 10 | }; 11 | } 12 | 13 | /** 14 | * Math.sign() 15 | * version 0.0.0 16 | * Browser Compatibility: 17 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign#browser_compatibility 18 | */ 19 | if (!Math.sign) { 20 | Math.sign = function (x) { 21 | // If x is NaN, the result is NaN. 22 | // If x is -0, the result is -0. 23 | // If x is +0, the result is +0. 24 | // If x is negative and not -0, the result is -1. 25 | // If x is positive and not +0, the result is +1. 26 | return ((x > 0) - (x < 0)) || +x; 27 | // A more aesthetic pseudo-representation: 28 | // 29 | // ( (x > 0) ? 1 : 0 ) // if x is positive, then positive one 30 | // + // else (because you can't be both - and +) 31 | // ( (x < 0) ? -1 : 0 ) // if x is negative, then negative one 32 | // || // if x is 0, -0, or NaN, or not a number, 33 | // +x // then the result will be x, (or) if x is 34 | // // not a number, then x converts to number 35 | }; 36 | } -------------------------------------------------------------------------------- /int-8-array.polyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Int8Array.prototype.from 3 | * version 0.0.0 4 | * Browser Compatibility: 5 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from#browser_compatibility 6 | */ 7 | if (!Int8Array.prototype.from) { 8 | (function () { 9 | Int8Array.prototype.from = function (obj, func, thisObj) { 10 | 11 | var typedArrayClass = Int8Array.prototype; 12 | if (typeof this !== 'function') { 13 | throw new TypeError('# is not a constructor'); 14 | } 15 | if (this.prototype !== typedArrayClass) { 16 | throw new TypeError('this is not a typed array.'); 17 | } 18 | 19 | func = func || function (elem) { 20 | return elem; 21 | }; 22 | 23 | if (typeof func !== 'function') { 24 | throw new TypeError('specified argument is not a function'); 25 | } 26 | 27 | obj = Object(obj); 28 | if (!obj['length']) { 29 | return new this(0); 30 | } 31 | var copy_data = []; 32 | for (var i = 0; i < obj.length; i++) { 33 | copy_data.push(obj[i]); 34 | } 35 | 36 | copy_data = copy_data.map(func, thisObj); 37 | 38 | var typed_array = new this(copy_data.length); 39 | for (var i = 0; i < typed_array.length; i++) { 40 | typed_array[i] = copy_data[i]; 41 | } 42 | return typed_array; 43 | } 44 | })(); 45 | } -------------------------------------------------------------------------------- /window.polyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * window.requestIdleCallback() 3 | * version 0.0.0 4 | * Browser Compatibility: 5 | * https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback#browser_compatibility 6 | */ 7 | if (!window.requestIdleCallback) { 8 | window.requestIdleCallback = function (callback, options) { 9 | var options = options || {}; 10 | var relaxation = 1; 11 | var timeout = options.timeout || relaxation; 12 | var start = performance.now(); 13 | return setTimeout(function () { 14 | callback({ 15 | get didTimeout() { 16 | return options.timeout ? false : (performance.now() - start) - relaxation > timeout; 17 | }, 18 | timeRemaining: function () { 19 | return Math.max(0, relaxation + (performance.now() - start)); 20 | }, 21 | }); 22 | }, relaxation); 23 | }; 24 | } 25 | 26 | /** 27 | * window.cancelIdleCallback() 28 | * version 0.0.0 29 | * Browser Compatibility: 30 | * https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelIdleCallback#browser_compatibility 31 | */ 32 | if (!window.cancelIdleCallback) { 33 | window.cancelIdleCallback = function (id) { 34 | clearTimeout(id); 35 | }; 36 | } 37 | 38 | /** 39 | * window.requestAnimationFrame() 40 | * version 0.0.0 41 | * Browser Compatibility: 42 | * https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#browser_compatibility 43 | */ 44 | if (!window.requestAnimationFrame) { 45 | window.requestAnimationFrame = function (callback) { 46 | return window.setTimeout(function () { 47 | callback(Date.now()); 48 | }, 1000 / 60); 49 | }; 50 | } 51 | 52 | /** 53 | * window.cancelAnimationFrame() 54 | * version 0.0.0 55 | * Browser Compatibility: 56 | * https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame#browser_compatibility 57 | */ 58 | if (!window.cancelAnimationFrame) { 59 | window.cancelAnimationFrame = function (id) { 60 | clearTimeout(id); 61 | }; 62 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Set of all Javascript polyfills 2 | 3 | Help us to be best 4 | 5 | [![Backers](https://opencollective.com/polyfill/tiers/backers.svg?avatarHeight=114&width=838)](https://opencollective.com/polyfill) 6 | 7 | ## Polyfill includes: 8 | 9 | Array, Date, Element, Function, Math, Number, String, Uint8Array and Window 10 | 11 | ## NPM 12 | 13 | ⚠️ We don't have any package in NPM! 14 | 15 | ### Array Polyfill: 16 | 17 | ```js 18 | Array.from; 19 | Array.isArray; 20 | Array.of; 21 | Array.prototype.at; 22 | Array.prototype.copyWithin; 23 | Array.prototype.entries; 24 | Array.prototype.every; 25 | Array.prototype.fill; 26 | Array.prototype.filter; 27 | Array.prototype.find; 28 | Array.prototype.findIndex; 29 | Array.prototype.flat; 30 | Array.prototype.flatMap; 31 | Array.prototype.forEach; 32 | Array.prototype.includes; 33 | Array.prototype.indexOf; 34 | Array.prototype.keys; 35 | Array.prototype.lastIndexOf; 36 | Array.prototype.map; 37 | Array.prototype.reduce; 38 | Array.prototype.reduceRight; 39 | Array.prototype.some; 40 | Array.prototype.toLocaleString; 41 | Array.prototype.values; 42 | ``` 43 | 44 | ### Date Polyfill: 45 | 46 | ```js 47 | Date.prototype.toISOString; 48 | ``` 49 | 50 | ### Function Polyfill: 51 | 52 | ```js 53 | Function.prototype.name; 54 | ``` 55 | 56 | ### Math Polyfill: 57 | 58 | ```js 59 | Math.sign; 60 | Math.trunc; 61 | ``` 62 | 63 | ### Number Polyfill: 64 | 65 | ```js 66 | Number.isInteger; 67 | ``` 68 | 69 | ### String Polyfill: 70 | 71 | ```js 72 | String.fromCodePoint; 73 | String.prototype.at; 74 | String.prototype.codePointAt; 75 | String.prototype.endsWith; 76 | String.prototype.includes; 77 | String.prototype.padEnd; 78 | String.prototype.padStart; 79 | String.prototype.repeat; 80 | String.prototype.startsWith; 81 | String.prototype.trim; 82 | ``` 83 | 84 | ### Uint8Array Polyfill: 85 | 86 | ```js 87 | Uint8Array.prototype.at; 88 | ``` 89 | 90 | ### window Polyfill: 91 | 92 | ```js 93 | window.requestIdleCallback; 94 | window.cancelIdleCallback; 95 | window.requestAnimationFrame; 96 | window.cancelAnimationFrame; 97 | ``` 98 | 99 | ## Backers 100 | 101 | [![Backers](https://opencollective.com/polyfill/tiers/backers.svg?avatarHeight=114&width=838)](https://opencollective.com/polyfill) 102 | 103 | -------------------------------------------------------------------------------- /string.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * String.prototype.at() 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support No No No No No No 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | if (!String.prototype.at) { 12 | Object.defineProperty(String.prototype, "at", 13 | { 14 | value: function (n) { 15 | // ToInteger() abstract op 16 | n = Math.trunc(n) || 0; 17 | // Allow negative indexing from the end 18 | if (n < 0) n += this.length; 19 | // OOB access is guaranteed to return undefined 20 | if (n < 0 || n >= this.length) return undefined; 21 | // Otherwise, this is just normal property access 22 | return this[n]; 23 | }, 24 | writable: true, 25 | enumerable: false, 26 | configurable: true 27 | }); 28 | } 29 | 30 | /** 31 | * String.fromCharCode() 32 | * version 0.0.0 33 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 34 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 35 | * ------------------------------------------------------------------------------- 36 | */ 37 | 38 | /** 39 | * String.fromCodePoint() 40 | * version 0.0.0 41 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 42 | * Basic support 41 29 (No) 28 10 ? 43 | * ------------------------------------------------------------------------------- 44 | */ 45 | if (!String.fromCodePoint) { 46 | var stringFromCharCode = String.fromCharCode; 47 | var floor = Math.floor; 48 | Object.defineProperty(String, 'fromCodePoint', { 49 | configurable: true, 50 | writable: true, 51 | value: function () { 52 | var MAX_SIZE = 0x4000; 53 | var codeUnits = []; 54 | var highSurrogate; 55 | var lowSurrogate; 56 | var index = -1; 57 | var length = arguments.length; 58 | if (!length) { 59 | return ''; 60 | } 61 | var result = ''; 62 | while (++index < length) { 63 | var codePoint = Number(arguments[index]); 64 | if ( 65 | !isFinite(codePoint) || 66 | codePoint < 0 || 67 | codePoint > 0x10ffff || 68 | floor(codePoint) != codePoint 69 | ) { 70 | throw RangeError('Invalid code point: ' + codePoint); 71 | } 72 | if (codePoint <= 0xffff) { 73 | // BMP code point 74 | codeUnits.push(codePoint); 75 | } else { 76 | codePoint -= 0x10000; 77 | highSurrogate = (codePoint >> 10) + 0xd800; 78 | lowSurrogate = (codePoint % 0x400) + 0xdc00; 79 | codeUnits.push(highSurrogate, lowSurrogate); 80 | } 81 | if (index + 1 == length || codeUnits.length > MAX_SIZE) { 82 | result += stringFromCharCode.apply(null, codeUnits); 83 | codeUnits.length = 0; 84 | } 85 | } 86 | return result; 87 | }, 88 | }); 89 | } 90 | 91 | /** 92 | * String.anchor() 93 | * version 0.0.0 94 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 95 | * Basic support (Yes) 1.0 (Yes) (Yes) (Yes) (Yes) 96 | * ------------------------------------------------------------------------------- 97 | */ 98 | 99 | /** 100 | * String.charAt() 101 | * version 0.0.0 102 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 103 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 104 | * ------------------------------------------------------------------------------- 105 | */ 106 | 107 | /** 108 | * String.charCodeAt() 109 | * version 0.0.0 110 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 111 | * Basic support (Yes) 1.0 (Yes) (Yes) (Yes) (Yes) 112 | * ------------------------------------------------------------------------------- 113 | */ 114 | 115 | /** 116 | * String.codePointAt() 117 | * version 0.0.0 118 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 119 | * Basic support 41 29 11 28 10 ? 120 | * ------------------------------------------------------------------------------- 121 | */ 122 | if (!String.prototype.codePointAt) { 123 | Object.defineProperty(String.prototype, 'codePointAt', { 124 | configurable: true, 125 | writable: true, 126 | value: function (position) { 127 | if (this == null) { 128 | throw TypeError(); 129 | } 130 | var string = String(this); 131 | var size = string.length; 132 | var index = position ? Number(position) : 0; 133 | if (index != index) { 134 | index = 0; 135 | } 136 | if (index < 0 || index >= size) { 137 | return undefined; 138 | } 139 | var first = string.charCodeAt(index); 140 | var second; 141 | if (first >= 0xd800 && first <= 0xdbff && size > index + 1) { 142 | second = string.charCodeAt(index + 1); 143 | if (second >= 0xdc00 && second <= 0xdfff) { 144 | return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000; 145 | } 146 | } 147 | return first; 148 | }, 149 | }); 150 | } 151 | 152 | /** 153 | * String.concat() 154 | * version 0.0.0 155 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 156 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 157 | * ------------------------------------------------------------------------------- 158 | */ 159 | 160 | /** 161 | * String.endsWith() 162 | * version 0.0.0 163 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 164 | * Basic support 41 17 (No) (No) 9 (Yes) 165 | * ------------------------------------------------------------------------------- 166 | */ 167 | if (!String.prototype.endsWith) { 168 | Object.defineProperty(String.prototype, 'endsWith', { 169 | configurable: true, 170 | writable: true, 171 | value: function (searchString, position) { 172 | var subjectString = this.toString(); 173 | if ( 174 | typeof position !== 'number' || 175 | !isFinite(position) || 176 | Math.floor(position) !== position || 177 | position > subjectString.length 178 | ) { 179 | position = subjectString.length; 180 | } 181 | position -= searchString.length; 182 | var lastIndex = subjectString.lastIndexOf(searchString, position); 183 | return lastIndex !== -1 && lastIndex === position; 184 | }, 185 | }); 186 | } 187 | 188 | /** 189 | * String.includes() 190 | * version 0.0.0 191 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 192 | * Basic support 41 40 (No) (No) 9 (Yes) 193 | * ------------------------------------------------------------------------------- 194 | */ 195 | if (!String.prototype.includes) { 196 | Object.defineProperty(String.prototype, 'includes', { 197 | configurable: true, 198 | writable: true, 199 | value: function (search, start) { 200 | if (typeof start !== 'number') { 201 | start = 0; 202 | } 203 | if (start + search.length > this.length) { 204 | return false; 205 | } else { 206 | return this.indexOf(search, start) !== -1; 207 | } 208 | }, 209 | }); 210 | } 211 | 212 | /** 213 | * String.indexOf() 214 | * version 0.0.0 215 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 216 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 217 | * ------------------------------------------------------------------------------- 218 | */ 219 | 220 | /** 221 | * String.lastIndexOf() 222 | * version 0.0.0 223 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 224 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 225 | * ------------------------------------------------------------------------------- 226 | */ 227 | 228 | /** 229 | * String.link() 230 | * version 0.0.0 231 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 232 | * Basic support (Yes) 1.0 (Yes) (Yes) (Yes) (Yes) 233 | * ------------------------------------------------------------------------------- 234 | */ 235 | 236 | /** 237 | * String.localeCompare() 238 | * version 0.0.0 239 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 240 | * Basic support (Yes) 1.0 (Yes) (Yes) (Yes) (Yes) 241 | * ------------------------------------------------------------------------------- 242 | */ 243 | 244 | /** 245 | * String.match() 246 | * version 0.0.0 247 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 248 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 249 | * ------------------------------------------------------------------------------- 250 | */ 251 | 252 | /** 253 | * String.normalize() 254 | * version 0.0.1 255 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 256 | * Basic support 34 31 (No) (Yes) 10 (Yes) 257 | * ------------------------------------------------------------------------------- 258 | */ 259 | if (!String.prototype.normalize) { 260 | // need polyfill 261 | } 262 | 263 | /** 264 | * String.padEnd() 265 | * version 1.0.1 266 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 267 | * Basic support 57 48 (No) 44 10 15 268 | * ------------------------------------------------------------------------------- 269 | */ 270 | if (!String.prototype.padEnd) { 271 | Object.defineProperty(String.prototype, 'padEnd', { 272 | configurable: true, 273 | writable: true, 274 | value: function (targetLength, padString) { 275 | targetLength = targetLength >> 0; //floor if number or convert non-number to 0; 276 | padString = String(typeof padString !== 'undefined' ? padString : ' '); 277 | if (this.length > targetLength) { 278 | return String(this); 279 | } else { 280 | targetLength = targetLength - this.length; 281 | if (targetLength > padString.length) { 282 | padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed 283 | } 284 | return String(this) + padString.slice(0, targetLength); 285 | } 286 | }, 287 | }); 288 | } 289 | 290 | /** 291 | * String.padStart() 292 | * version 1.0.1 293 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 294 | * Basic support 57 51 (No) 44 10 15 295 | * ------------------------------------------------------------------------------- 296 | */ 297 | if (!String.prototype.padStart) { 298 | Object.defineProperty(String.prototype, 'padStart', { 299 | configurable: true, 300 | writable: true, 301 | value: function (targetLength, padString) { 302 | targetLength = targetLength >> 0; //floor if number or convert non-number to 0; 303 | padString = String(typeof padString !== 'undefined' ? padString : ' '); 304 | if (this.length > targetLength) { 305 | return String(this); 306 | } else { 307 | targetLength = targetLength - this.length; 308 | if (targetLength > padString.length) { 309 | padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed 310 | } 311 | return padString.slice(0, targetLength) + String(this); 312 | } 313 | }, 314 | }); 315 | } 316 | 317 | /** 318 | * String.repeat() 319 | * version 0.0.0 320 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 321 | * Basic support 41 24 (No) (Yes) 9 (Yes) 322 | * ------------------------------------------------------------------------------- 323 | */ 324 | if (!String.prototype.repeat) { 325 | Object.defineProperty(String.prototype, 'repeat', { 326 | configurable: true, 327 | writable: true, 328 | value: function (count) { 329 | if (this == null) { 330 | throw new TypeError("can't convert " + this + ' to object'); 331 | } 332 | var str = '' + this; 333 | count = +count; 334 | if (count != count) { 335 | count = 0; 336 | } 337 | if (count < 0) { 338 | throw new RangeError('repeat count must be non-negative'); 339 | } 340 | if (count == Infinity) { 341 | throw new RangeError('repeat count must be less than infinity'); 342 | } 343 | count = Math.floor(count); 344 | if (str.length == 0 || count == 0) { 345 | return ''; 346 | } 347 | if (str.length * count >= 1 << 28) { 348 | throw new RangeError( 349 | 'repeat count must not overflow maximum string size' 350 | ); 351 | } 352 | var rpt = ''; 353 | for (; ;) { 354 | if ((count & 1) == 1) { 355 | rpt += str; 356 | } 357 | count >>>= 1; 358 | if (count == 0) { 359 | break; 360 | } 361 | str += str; 362 | } 363 | return rpt; 364 | }, 365 | }); 366 | } 367 | 368 | /** 369 | * String.search() 370 | * version 0.0.0 371 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 372 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 373 | * ------------------------------------------------------------------------------- 374 | */ 375 | 376 | /** 377 | * String.slice() 378 | * version 0.0.0 379 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 380 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 381 | * ------------------------------------------------------------------------------- 382 | */ 383 | 384 | /** 385 | * String.split() 386 | * version 0.0.0 387 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 388 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 389 | * ------------------------------------------------------------------------------- 390 | */ 391 | 392 | /** 393 | * String.startsWith() 394 | * version 0.0.0 395 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 396 | * Basic support 41 17 (No) 28 9 (Yes) 397 | * ------------------------------------------------------------------------------- 398 | */ 399 | if (!String.prototype.startsWith) { 400 | Object.defineProperty(String.prototype, 'startsWith', { 401 | configurable: true, 402 | writable: true, 403 | value: function (searchString, position) { 404 | position = position || 0; 405 | return this.substr(position, searchString.length) === searchString; 406 | }, 407 | }); 408 | } 409 | 410 | /** 411 | * String.substr() 412 | * version 0.0.0 413 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 414 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 415 | * ------------------------------------------------------------------------------- 416 | */ 417 | 418 | /** 419 | * String.substring() 420 | * version 0.0.0 421 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 422 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 423 | * ------------------------------------------------------------------------------- 424 | */ 425 | 426 | /** 427 | * String.toLocaleLowerCase() 428 | * version 0.0.0 429 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 430 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 431 | * ------------------------------------------------------------------------------- 432 | */ 433 | 434 | /** 435 | * String.toLocaleUpperCase() 436 | * version 0.0.0 437 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 438 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 439 | * ------------------------------------------------------------------------------- 440 | */ 441 | 442 | /** 443 | * String.toLowerCase() 444 | * version 0.0.0 445 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 446 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 447 | * ------------------------------------------------------------------------------- 448 | */ 449 | 450 | /** 451 | * String.toString() 452 | * version 0.0.0 453 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 454 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 455 | * ------------------------------------------------------------------------------- 456 | */ 457 | 458 | /** 459 | * String.toUpperCase() 460 | * version 0.0.0 461 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 462 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 463 | * ------------------------------------------------------------------------------- 464 | */ 465 | 466 | /** 467 | * String.trim() 468 | * version 0.0.0 469 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 470 | * Basic support (Yes) 3.5 9 10.5 5 ? 471 | * ------------------------------------------------------------------------------- 472 | */ 473 | if (!String.prototype.trim) { 474 | Object.defineProperty(String.prototype, 'trim', { 475 | configurable: true, 476 | writable: true, 477 | value: function () { 478 | return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); 479 | }, 480 | }); 481 | } 482 | 483 | /** 484 | * String.trimLeft() 485 | * version 0.0.0 486 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 487 | * Basic support (Yes) 3.5 (No) ? ? ? 488 | * ------------------------------------------------------------------------------- 489 | */ 490 | 491 | /** 492 | * String.trimRight() 493 | * version 0.0.0 494 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 495 | * Basic support (Yes) 3.5 (No) ? ? ? 496 | * ------------------------------------------------------------------------------- 497 | */ 498 | 499 | /** 500 | * String.valueOf() 501 | * version 0.0.0 502 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 503 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 504 | * ------------------------------------------------------------------------------- 505 | */ 506 | 507 | /** 508 | * String.raw 509 | * version 0.0.0 510 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 511 | * Basic support 41 34 (No) (No) 10 ? 512 | * ------------------------------------------------------------------------------- 513 | */ 514 | -------------------------------------------------------------------------------- /array.polyfill.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | /** 5 | * Array.prototype.findLastIndex() 6 | * version 0.0.0 7 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 8 | * Basic support No No No No No No 9 | * ------------------------------------------------------------------------------- 10 | */ 11 | if (!Array.prototype.findLastIndex) { 12 | Object.defineProperty(Array.prototype, "findLastIndex", 13 | { 14 | value: function (predicate, thisArg) { 15 | let idx = this.length - 1; 16 | while (idx >= 0) { 17 | const value = this[idx]; 18 | if (predicate.call(thisArg, value, idx, this)) { 19 | return idx; 20 | } 21 | idx--; 22 | } 23 | return -1; 24 | } 25 | , 26 | writable: true, 27 | enumerable: false, 28 | configurable: true 29 | }); 30 | } 31 | 32 | /** 33 | * Array.prototype.findLast() 34 | * version 0.0.0 35 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 36 | * Basic support No No No No No No 37 | * ------------------------------------------------------------------------------- 38 | */ 39 | if (!Array.prototype.findLast) { 40 | Object.defineProperty(Array.prototype, "findLast", 41 | { 42 | value: function (predicate, thisArg) { 43 | let idx = this.length - 1; 44 | while (idx >= 0) { 45 | const value = this[idx]; 46 | if (predicate.call(thisArg, value, idx, this)) { 47 | return value; 48 | } 49 | idx--; 50 | } 51 | return undefined; 52 | } 53 | , 54 | writable: true, 55 | enumerable: false, 56 | configurable: true 57 | }); 58 | } 59 | 60 | /** 61 | * Array.prototype.at() 62 | * version 0.0.0 63 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 64 | * Basic support No No No No No No 65 | * ------------------------------------------------------------------------------- 66 | */ 67 | if (!Array.prototype.at) { 68 | Object.defineProperty(Array.prototype, "at", 69 | { 70 | value: function (n) { 71 | // ToInteger() abstract op 72 | n = Math.trunc(n) || 0; 73 | // Allow negative indexing from the end 74 | if (n < 0) n += this.length; 75 | // OOB access is guaranteed to return undefined 76 | if (n < 0 || n >= this.length) return undefined; 77 | // Otherwise, this is just normal property access 78 | return this[n]; 79 | }, 80 | writable: true, 81 | enumerable: false, 82 | configurable: true 83 | }); 84 | } 85 | 86 | /** 87 | * Array.prototype.from() 88 | * version 0.0.0 89 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 90 | * Basic support 45 32 (No) (Yes) 9 (Yes) 91 | * ------------------------------------------------------------------------------- 92 | */ 93 | if (!Array.from) { 94 | Array.from = (function () { 95 | var toStr = Object.prototype.toString; 96 | var isCallable = function (fn) { 97 | return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; 98 | }; 99 | var toInteger = function (value) { 100 | var number = Number(value); 101 | if (isNaN(number)) { 102 | return 0; 103 | } 104 | if (number === 0 || !isFinite(number)) { 105 | return number; 106 | } 107 | return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); 108 | }; 109 | var maxSafeInteger = Math.pow(2, 53) - 1; 110 | var toLength = function (value) { 111 | var len = toInteger(value); 112 | return Math.min(Math.max(len, 0), maxSafeInteger); 113 | }; 114 | 115 | // The length property of the from method is 1. 116 | return function from(arrayLike /*, mapFn, thisArg */) { 117 | // 1. Let C be the this value. 118 | var C = this; 119 | 120 | // 2. Let items be ToObject(arrayLike). 121 | var items = Object(arrayLike); 122 | 123 | // 3. ReturnIfAbrupt(items). 124 | if (arrayLike == null) { 125 | throw new TypeError( 126 | 'Array.from requires an array-like object - not null or undefined' 127 | ); 128 | } 129 | 130 | // 4. If mapfn is undefined, then let mapping be false. 131 | var mapFn = arguments.length > 1 ? arguments[1] : void undefined; 132 | var T; 133 | if (typeof mapFn !== 'undefined') { 134 | // 5. else 135 | // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. 136 | if (!isCallable(mapFn)) { 137 | throw new TypeError( 138 | 'Array.from: when provided, the second argument must be a function' 139 | ); 140 | } 141 | 142 | // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. 143 | if (arguments.length > 2) { 144 | T = arguments[2]; 145 | } 146 | } 147 | 148 | // 10. Let lenValue be Get(items, "length"). 149 | // 11. Let len be ToLength(lenValue). 150 | var len = toLength(items.length); 151 | 152 | // 13. If IsConstructor(C) is true, then 153 | // 13. a. Let A be the result of calling the [[Construct]] internal method 154 | // of C with an argument list containing the single item len. 155 | // 14. a. Else, Let A be ArrayCreate(len). 156 | var A = isCallable(C) ? Object(new C(len)) : new Array(len); 157 | 158 | // 16. Let k be 0. 159 | var k = 0; 160 | // 17. Repeat, while k < len… (also steps a - h) 161 | var kValue; 162 | while (k < len) { 163 | kValue = items[k]; 164 | if (mapFn) { 165 | A[k] = 166 | typeof T === 'undefined' 167 | ? mapFn(kValue, k) 168 | : mapFn.call(T, kValue, k); 169 | } else { 170 | A[k] = kValue; 171 | } 172 | k += 1; 173 | } 174 | // 18. Let putStatus be Put(A, "length", len, true). 175 | A.length = len; 176 | // 20. Return A. 177 | return A; 178 | }; 179 | })(); 180 | } 181 | 182 | /** 183 | * Array.prototype.isArray() 184 | * version 0.0.0 185 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 186 | * Basic support 5 4 9 10.5 5 (Yes) 187 | * ------------------------------------------------------------------------------- 188 | */ 189 | if (!Array.isArray) { 190 | Array.isArray = function (arg) { 191 | return Object.prototype.toString.call(arg) === '[object Array]'; 192 | }; 193 | } 194 | 195 | /** 196 | * Array.prototype.of() 197 | * version 0.0.0 198 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 199 | * Basic support 45 25 (No) (No) 9 (Yes) 200 | * ------------------------------------------------------------------------------- 201 | */ 202 | if (!Array.of) { 203 | Array.of = function () { 204 | return Array.prototype.slice.call(arguments); 205 | }; 206 | } 207 | 208 | /** 209 | * Array.prototype.copyWithin() 210 | * version 0.0.0 211 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 212 | * Basic support 45 32 (No) 32 9 12 213 | * ------------------------------------------------------------------------------- 214 | */ 215 | if (!Array.prototype.copyWithin) { 216 | Object.defineProperty(Array.prototype, 'copyWithin', { 217 | configurable: true, 218 | writable: true, 219 | value: function (target, start /*, end*/) { 220 | // Steps 1-2. 221 | if (this == null) { 222 | throw new TypeError('this is null or not defined'); 223 | } 224 | 225 | var O = Object(this); 226 | 227 | // Steps 3-5. 228 | var len = O.length >>> 0; 229 | 230 | // Steps 6-8. 231 | var relativeTarget = target >> 0; 232 | 233 | var to = 234 | relativeTarget < 0 235 | ? Math.max(len + relativeTarget, 0) 236 | : Math.min(relativeTarget, len); 237 | 238 | // Steps 9-11. 239 | var relativeStart = start >> 0; 240 | 241 | var from = 242 | relativeStart < 0 243 | ? Math.max(len + relativeStart, 0) 244 | : Math.min(relativeStart, len); 245 | 246 | // Steps 12-14. 247 | var end = arguments[2]; 248 | var relativeEnd = end === undefined ? len : end >> 0; 249 | 250 | var final = 251 | relativeEnd < 0 252 | ? Math.max(len + relativeEnd, 0) 253 | : Math.min(relativeEnd, len); 254 | 255 | // Step 15. 256 | var count = Math.min(final - from, len - to); 257 | 258 | // Steps 16-17. 259 | var direction = 1; 260 | 261 | if (from < to && to < from + count) { 262 | direction = -1; 263 | from += count - 1; 264 | to += count - 1; 265 | } 266 | 267 | // Step 18. 268 | while (count > 0) { 269 | if (from in O) { 270 | O[to] = O[from]; 271 | } else { 272 | delete O[to]; 273 | } 274 | 275 | from += direction; 276 | to += direction; 277 | count--; 278 | } 279 | 280 | // Step 19. 281 | return O; 282 | }, 283 | }); 284 | } 285 | 286 | /** 287 | * Array.prototype.entries() 288 | * version 0.0.0 289 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 290 | * Basic support 38 28 (No) 25 7.1 ? 291 | * ------------------------------------------------------------------------------- 292 | */ 293 | if (!Array.prototype.entries) { 294 | Array.prototype.entries = function () { 295 | function Iterator() { } 296 | 297 | Iterator.prototype.next = function () { 298 | if (index > selfThis.length - 1) { 299 | done = true; 300 | } 301 | if (done) { 302 | return { value: undefined, done: true }; 303 | } 304 | return { value: [index, selfThis[index++]], done: false }; 305 | }; 306 | 307 | var selfThis = this; 308 | var index = 0; 309 | var done; 310 | 311 | return new Iterator(); 312 | }; 313 | } 314 | 315 | /** 316 | * Array.prototype.every() 317 | * version 0.0.0 318 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 319 | * Basic support (Yes) 1.5 9 (Yes) (Yes) ? 320 | * ------------------------------------------------------------------------------- 321 | */ 322 | if (!Array.prototype.every) { 323 | Object.defineProperty(Array.prototype, 'every', { 324 | configurable: true, 325 | writable: true, 326 | value: function (callbackfn, thisArg) { 327 | var T, k; 328 | 329 | if (this == null) { 330 | throw new TypeError('this is null or not defined'); 331 | } 332 | 333 | // 1. Let O be the result of calling ToObject passing the this 334 | // value as the argument. 335 | var O = Object(this); 336 | 337 | // 2. Let lenValue be the result of calling the Get internal method 338 | // of O with the argument "length". 339 | // 3. Let len be ToUint32(lenValue). 340 | var len = O.length >>> 0; 341 | 342 | // 4. If IsCallable(callbackfn) is false, throw a TypeError exception. 343 | if (typeof callbackfn !== 'function') { 344 | throw new TypeError(); 345 | } 346 | 347 | // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. 348 | if (arguments.length > 1) { 349 | T = thisArg; 350 | } 351 | 352 | // 6. Let k be 0. 353 | k = 0; 354 | 355 | // 7. Repeat, while k < len 356 | while (k < len) { 357 | var kValue; 358 | 359 | // a. Let Pk be ToString(k). 360 | // This is implicit for LHS operands of the in operator 361 | // b. Let kPresent be the result of calling the HasProperty internal 362 | // method of O with argument Pk. 363 | // This step can be combined with c 364 | // c. If kPresent is true, then 365 | if (k in O) { 366 | // i. Let kValue be the result of calling the Get internal method 367 | // of O with argument Pk. 368 | kValue = O[k]; 369 | 370 | // ii. Let testResult be the result of calling the Call internal method 371 | // of callbackfn with T as the this value and argument list 372 | // containing kValue, k, and O. 373 | var testResult = callbackfn.call(T, kValue, k, O); 374 | 375 | // iii. If ToBoolean(testResult) is false, return false. 376 | if (!testResult) { 377 | return false; 378 | } 379 | } 380 | k++; 381 | } 382 | return true; 383 | }, 384 | }); 385 | } 386 | 387 | /** 388 | * Array.prototype.fill() 389 | * version 0.0.0 390 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 391 | * Basic support 45 31 (No) (No) 7.1 (Yes) 392 | * ------------------------------------------------------------------------------- 393 | */ 394 | if (!Array.prototype.fill) { 395 | Object.defineProperty(Array.prototype, 'fill', { 396 | configurable: true, 397 | writable: true, 398 | value: function (value) { 399 | // Steps 1-2. 400 | if (this == null) { 401 | throw new TypeError('this is null or not defined'); 402 | } 403 | 404 | var O = Object(this); 405 | 406 | // Steps 3-5. 407 | var len = O.length >>> 0; 408 | 409 | // Steps 6-7. 410 | var start = arguments[1]; 411 | var relativeStart = start >> 0; 412 | 413 | // Step 8. 414 | var k = 415 | relativeStart < 0 416 | ? Math.max(len + relativeStart, 0) 417 | : Math.min(relativeStart, len); 418 | 419 | // Steps 9-10. 420 | var end = arguments[2]; 421 | var relativeEnd = end === undefined ? len : end >> 0; 422 | 423 | // Step 11. 424 | var final = 425 | relativeEnd < 0 426 | ? Math.max(len + relativeEnd, 0) 427 | : Math.min(relativeEnd, len); 428 | 429 | // Step 12. 430 | while (k < final) { 431 | O[k] = value; 432 | k++; 433 | } 434 | 435 | // Step 13. 436 | return O; 437 | }, 438 | }); 439 | } 440 | 441 | /** 442 | * Array.prototype.filter() 443 | * version 0.0.0 444 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 445 | * Basic support (Yes) 1.5 9 (Yes) (Yes) ? 446 | * ------------------------------------------------------------------------------- 447 | */ 448 | if (!Array.prototype.filter) { 449 | Object.defineProperty(Array.prototype, 'filter', { 450 | configurable: true, 451 | writable: true, 452 | value: function (fun /*, thisArg*/) { 453 | if (this === void 0 || this === null) { 454 | throw new TypeError(); 455 | } 456 | 457 | var t = Object(this); 458 | var len = t.length >>> 0; 459 | if (typeof fun !== 'function') { 460 | throw new TypeError(); 461 | } 462 | 463 | var res = []; 464 | var thisArg = arguments.length >= 2 ? arguments[1] : void 0; 465 | for (var i = 0; i < len; i++) { 466 | if (i in t) { 467 | var val = t[i]; 468 | 469 | // NOTE: Technically this should Object.defineProperty at 470 | // the next index, as push can be affected by 471 | // properties on Object.prototype and Array.prototype. 472 | // But that method's new, and collisions should be 473 | // rare, so use the more-compatible alternative. 474 | if (fun.call(thisArg, val, i, t)) { 475 | res.push(val); 476 | } 477 | } 478 | } 479 | 480 | return res; 481 | }, 482 | }); 483 | } 484 | 485 | /** 486 | * Array.prototype.find() 487 | * version 0.0.0 488 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 489 | * Basic support 45 25 (No) 32 7.1 12 490 | * ------------------------------------------------------------------------------- 491 | */ 492 | if (!Array.prototype.find) { 493 | Object.defineProperty(Array.prototype, 'find', { 494 | configurable: true, 495 | writable: true, 496 | value: function (predicate) { 497 | // 1. Let O be ? ToObject(this value). 498 | if (this == null) { 499 | throw new TypeError('"this" is null or not defined'); 500 | } 501 | 502 | var o = Object(this); 503 | 504 | // 2. Let len be ? ToLength(? Get(O, "length")). 505 | var len = o.length >>> 0; 506 | 507 | // 3. If IsCallable(predicate) is false, throw a TypeError exception. 508 | if (typeof predicate !== 'function') { 509 | throw new TypeError('predicate must be a function'); 510 | } 511 | 512 | // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. 513 | var thisArg = arguments[1]; 514 | 515 | // 5. Let k be 0. 516 | var k = 0; 517 | 518 | // 6. Repeat, while k < len 519 | while (k < len) { 520 | // a. Let Pk be ! ToString(k). 521 | // b. Let kValue be ? Get(O, Pk). 522 | // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). 523 | // d. If testResult is true, return kValue. 524 | var kValue = o[k]; 525 | if (predicate.call(thisArg, kValue, k, o)) { 526 | return kValue; 527 | } 528 | // e. Increase k by 1. 529 | k++; 530 | } 531 | 532 | // 7. Return undefined. 533 | return undefined; 534 | }, 535 | }); 536 | } 537 | 538 | /** 539 | * Array.prototype.findIndex() 540 | * version 0.0.0 541 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 542 | * Basic support 45 25 (No) (Yes) 7.1 (Yes) 543 | * ------------------------------------------------------------------------------- 544 | */ 545 | if (!Array.prototype.findIndex) { 546 | Object.defineProperty(Array.prototype, 'findIndex', { 547 | configurable: true, 548 | writable: true, 549 | value: function (predicate) { 550 | // 1. Let O be ? ToObject(this value). 551 | if (this == null) { 552 | throw new TypeError('"this" is null or not defined'); 553 | } 554 | 555 | var o = Object(this); 556 | 557 | // 2. Let len be ? ToLength(? Get(O, "length")). 558 | var len = o.length >>> 0; 559 | 560 | // 3. If IsCallable(predicate) is false, throw a TypeError exception. 561 | if (typeof predicate !== 'function') { 562 | throw new TypeError('predicate must be a function'); 563 | } 564 | 565 | // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. 566 | var thisArg = arguments[1]; 567 | 568 | // 5. Let k be 0. 569 | var k = 0; 570 | 571 | // 6. Repeat, while k < len 572 | while (k < len) { 573 | // a. Let Pk be ! ToString(k). 574 | // b. Let kValue be ? Get(O, Pk). 575 | // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). 576 | // d. If testResult is true, return k. 577 | var kValue = o[k]; 578 | if (predicate.call(thisArg, kValue, k, o)) { 579 | return k; 580 | } 581 | // e. Increase k by 1. 582 | k++; 583 | } 584 | 585 | // 7. Return -1. 586 | return -1; 587 | }, 588 | }); 589 | } 590 | 591 | /** 592 | * Array.prototype.flat() 593 | * version 0.0.0 594 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 595 | * Basic support 69 62 (No) 56 12 (No) 596 | * ------------------------------------------------------------------------------- 597 | */ 598 | if (!Array.prototype.flat) { 599 | Object.defineProperty(Array.prototype, 'flat', { 600 | configurable: true, 601 | writable: true, 602 | value: function () { 603 | var depth = 604 | typeof arguments[0] === 'undefined' ? 1 : Number(arguments[0]) || 0; 605 | var result = []; 606 | var forEach = result.forEach; 607 | 608 | var flatDeep = function (arr, depth) { 609 | forEach.call(arr, function (val) { 610 | if (depth > 0 && Array.isArray(val)) { 611 | flatDeep(val, depth - 1); 612 | } else { 613 | result.push(val); 614 | } 615 | }); 616 | }; 617 | 618 | flatDeep(this, depth); 619 | return result; 620 | }, 621 | }); 622 | } 623 | 624 | /** 625 | * Array.prototype.flatMap() 626 | * version 0.0.0 627 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 628 | * Basic support 69 62 (No) 56 12 (No) 629 | * ------------------------------------------------------------------------------- 630 | */ 631 | if (!Array.prototype.flatMap) { 632 | Object.defineProperty(Array.prototype, 'flatMap', { 633 | configurable: true, 634 | writable: true, 635 | value: function () { 636 | return Array.prototype.map.apply(this, arguments).flat(1); 637 | }, 638 | }); 639 | } 640 | 641 | /** 642 | * Array.prototype.forEach() 643 | * version 0.0.0 644 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 645 | * Basic support (Yes) 1.5 9 (Yes) (Yes) ? 646 | * ------------------------------------------------------------------------------- 647 | */ 648 | if (!Array.prototype.forEach) { 649 | Object.defineProperty(Array.prototype, 'forEach', { 650 | configurable: true, 651 | writable: true, 652 | value: function (callback /*, thisArg*/) { 653 | var T, k; 654 | 655 | if (this == null) { 656 | throw new TypeError('this is null or not defined'); 657 | } 658 | 659 | // 1. Let O be the result of calling toObject() passing the 660 | // |this| value as the argument. 661 | var O = Object(this); 662 | 663 | // 2. Let lenValue be the result of calling the Get() internal 664 | // method of O with the argument "length". 665 | // 3. Let len be toUint32(lenValue). 666 | var len = O.length >>> 0; 667 | 668 | // 4. If isCallable(callback) is false, throw a TypeError exception. 669 | // See: http://es5.github.com/#x9.11 670 | if (typeof callback !== 'function') { 671 | throw new TypeError(callback + ' is not a function'); 672 | } 673 | 674 | // 5. If thisArg was supplied, let T be thisArg; else let 675 | // T be undefined. 676 | if (arguments.length > 1) { 677 | T = arguments[1]; 678 | } 679 | 680 | // 6. Let k be 0 681 | k = 0; 682 | 683 | // 7. Repeat, while k < len 684 | while (k < len) { 685 | var kValue; 686 | 687 | // a. Let Pk be ToString(k). 688 | // This is implicit for LHS operands of the in operator 689 | // b. Let kPresent be the result of calling the HasProperty 690 | // internal method of O with argument Pk. 691 | // This step can be combined with c 692 | // c. If kPresent is true, then 693 | if (k in O) { 694 | // i. Let kValue be the result of calling the Get internal 695 | // method of O with argument Pk. 696 | kValue = O[k]; 697 | 698 | // ii. Call the Call internal method of callback with T as 699 | // the this value and argument list containing kValue, k, and O. 700 | callback.call(T, kValue, k, O); 701 | } 702 | // d. Increase k by 1. 703 | k++; 704 | } 705 | // 8. return undefined 706 | }, 707 | }); 708 | } 709 | 710 | /** 711 | * Array.prototype.includes() 712 | * version 0.0.0 713 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 714 | * Basic support 47 43 (No) 34 9 14 715 | * ------------------------------------------------------------------------------- 716 | */ 717 | if (!Array.prototype.includes) { 718 | Object.defineProperty(Array.prototype, 'includes', { 719 | configurable: true, 720 | writable: true, 721 | value: function (searchElement, fromIndex) { 722 | // 1. Let O be ? ToObject(this value). 723 | if (this == null) { 724 | throw new TypeError('"this" is null or not defined'); 725 | } 726 | 727 | var o = Object(this); 728 | 729 | // 2. Let len be ? ToLength(? Get(O, "length")). 730 | var len = o.length >>> 0; 731 | 732 | // 3. If len is 0, return false. 733 | if (len === 0) { 734 | return false; 735 | } 736 | 737 | // 4. Let n be ? ToInteger(fromIndex). 738 | // (If fromIndex is undefined, this step produces the value 0.) 739 | var n = fromIndex | 0; 740 | 741 | // 5. If n ≥ 0, then 742 | // a. Let k be n. 743 | // 6. Else n < 0, 744 | // a. Let k be len + n. 745 | // b. If k < 0, let k be 0. 746 | var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 747 | 748 | function sameValueZero(x, y) { 749 | return ( 750 | x === y || 751 | (typeof x === 'number' && 752 | typeof y === 'number' && 753 | isNaN(x) && 754 | isNaN(y)) 755 | ); 756 | } 757 | 758 | // 7. Repeat, while k < len 759 | while (k < len) { 760 | // a. Let elementK be the result of ? Get(O, ! ToString(k)). 761 | // b. If SameValueZero(searchElement, elementK) is true, return true. 762 | // c. Increase k by 1. 763 | if (sameValueZero(o[k], searchElement)) { 764 | return true; 765 | } 766 | k++; 767 | } 768 | 769 | // 8. Return false 770 | return false; 771 | }, 772 | }); 773 | } 774 | 775 | /** 776 | * Array.prototype.indexOf() 777 | * version 0.0.0 778 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 779 | * Basic support (Yes) 1.5 9 (Yes) (Yes) ? 780 | * ------------------------------------------------------------------------------- 781 | */ 782 | if (!Array.prototype.indexOf) { 783 | Object.defineProperty(Array.prototype, 'indexOf', { 784 | configurable: true, 785 | writable: true, 786 | value: function (searchElement, fromIndex) { 787 | var k; 788 | 789 | // 1. Let o be the result of calling ToObject passing 790 | // the this value as the argument. 791 | if (this == null) { 792 | throw new TypeError('"this" is null or not defined'); 793 | } 794 | 795 | var o = Object(this); 796 | 797 | // 2. Let lenValue be the result of calling the Get 798 | // internal method of o with the argument "length". 799 | // 3. Let len be ToUint32(lenValue). 800 | var len = o.length >>> 0; 801 | 802 | // 4. If len is 0, return -1. 803 | if (len === 0) { 804 | return -1; 805 | } 806 | 807 | // 5. If argument fromIndex was passed let n be 808 | // ToInteger(fromIndex); else let n be 0. 809 | var n = fromIndex | 0; 810 | 811 | // 6. If n >= len, return -1. 812 | if (n >= len) { 813 | return -1; 814 | } 815 | 816 | // 7. If n >= 0, then Let k be n. 817 | // 8. Else, n<0, Let k be len - abs(n). 818 | // If k is less than 0, then let k be 0. 819 | k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 820 | 821 | // 9. Repeat, while k < len 822 | while (k < len) { 823 | // a. Let Pk be ToString(k). 824 | // This is implicit for LHS operands of the in operator 825 | // b. Let kPresent be the result of calling the 826 | // HasProperty internal method of o with argument Pk. 827 | // This step can be combined with c 828 | // c. If kPresent is true, then 829 | // i. Let elementK be the result of calling the Get 830 | // internal method of o with the argument ToString(k). 831 | // ii. Let same be the result of applying the 832 | // Strict Equality Comparison Algorithm to 833 | // searchElement and elementK. 834 | // iii. If same is true, return k. 835 | if (k in o && o[k] === searchElement) { 836 | return k; 837 | } 838 | k++; 839 | } 840 | return -1; 841 | }, 842 | }); 843 | } 844 | 845 | /** 846 | * Array.prototype.join() 847 | * version 0.0.0 848 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 849 | * Basic support 1 1 5.5 (Yes) (Yes) ? 850 | * ------------------------------------------------------------------------------- 851 | */ 852 | 853 | /** 854 | * Array.prototype.keys() 855 | * version 0.0.0 856 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 857 | * Basic support 38 28 (No) 25 7.1 (Yes) 858 | * ------------------------------------------------------------------------------- 859 | */ 860 | if (!Array.prototype.keys) { 861 | Array.prototype.keys = function () { 862 | function Iterator() { } 863 | 864 | Iterator.prototype.next = function () { 865 | if (index > selfThis.length - 1) { 866 | done = true; 867 | } 868 | if (done) { 869 | return { value: undefined, done: true }; 870 | } 871 | return { value: index++, done: false }; 872 | }; 873 | 874 | var selfThis = this; 875 | var index = 0; 876 | var done; 877 | 878 | return new Iterator(); 879 | }; 880 | } 881 | 882 | /** 883 | * Array.prototype.lastIndexOf() 884 | * version 0.0.0 885 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 886 | * Basic support (Yes) (Yes) 9 (Yes) (Yes) ? 887 | * ------------------------------------------------------------------------------- 888 | */ 889 | if (!Array.prototype.lastIndexOf) { 890 | Object.defineProperty(Array.prototype, 'lastIndexOf', { 891 | configurable: true, 892 | writable: true, 893 | value: function (searchElement /*, fromIndex*/) { 894 | if (this === void 0 || this === null) { 895 | throw new TypeError(); 896 | } 897 | 898 | var n, 899 | k, 900 | t = Object(this), 901 | len = t.length >>> 0; 902 | if (len === 0) { 903 | return -1; 904 | } 905 | 906 | n = len - 1; 907 | if (arguments.length > 1) { 908 | n = Number(arguments[1]); 909 | if (n != n) { 910 | n = 0; 911 | } else if (n != 0 && n != 1 / 0 && n != -(1 / 0)) { 912 | n = (n > 0 || -1) * Math.floor(Math.abs(n)); 913 | } 914 | } 915 | 916 | for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--) { 917 | if (k in t && t[k] === searchElement) { 918 | return k; 919 | } 920 | } 921 | return -1; 922 | }, 923 | }); 924 | } 925 | 926 | /** 927 | * Array.prototype.map() 928 | * version 0.0.0 929 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 930 | * Basic support (Yes) 1.5 9 (Yes) (Yes) ? 931 | * ------------------------------------------------------------------------------- 932 | */ 933 | if (!Array.prototype.map) { 934 | Object.defineProperty(Array.prototype, 'map', { 935 | configurable: true, 936 | writable: true, 937 | value: function (callback /*, thisArg*/) { 938 | var T, A, k; 939 | 940 | if (this == null) { 941 | throw new TypeError('this is null or not defined'); 942 | } 943 | 944 | // 1. Let O be the result of calling ToObject passing the |this| 945 | // value as the argument. 946 | var O = Object(this); 947 | 948 | // 2. Let lenValue be the result of calling the Get internal 949 | // method of O with the argument "length". 950 | // 3. Let len be ToUint32(lenValue). 951 | var len = O.length >>> 0; 952 | 953 | // 4. If IsCallable(callback) is false, throw a TypeError exception. 954 | // See: http://es5.github.com/#x9.11 955 | if (typeof callback !== 'function') { 956 | throw new TypeError(callback + ' is not a function'); 957 | } 958 | 959 | // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. 960 | if (arguments.length > 1) { 961 | T = arguments[1]; 962 | } 963 | 964 | // 6. Let A be a new array created as if by the expression new Array(len) 965 | // where Array is the standard built-in constructor with that name and 966 | // len is the value of len. 967 | A = new Array(len); 968 | 969 | // 7. Let k be 0 970 | k = 0; 971 | 972 | // 8. Repeat, while k < len 973 | while (k < len) { 974 | var kValue, mappedValue; 975 | 976 | // a. Let Pk be ToString(k). 977 | // This is implicit for LHS operands of the in operator 978 | // b. Let kPresent be the result of calling the HasProperty internal 979 | // method of O with argument Pk. 980 | // This step can be combined with c 981 | // c. If kPresent is true, then 982 | if (k in O) { 983 | // i. Let kValue be the result of calling the Get internal 984 | // method of O with argument Pk. 985 | kValue = O[k]; 986 | 987 | // ii. Let mappedValue be the result of calling the Call internal 988 | // method of callback with T as the this value and argument 989 | // list containing kValue, k, and O. 990 | mappedValue = callback.call(T, kValue, k, O); 991 | 992 | // iii. Call the DefineOwnProperty internal method of A with arguments 993 | // Pk, Property Descriptor 994 | // { Value: mappedValue, 995 | // Writable: true, 996 | // Enumerable: true, 997 | // Configurable: true }, 998 | // and false. 999 | 1000 | // In browsers that support Object.defineProperty, use the following: 1001 | // Object.defineProperty(A, k, { 1002 | // value: mappedValue, 1003 | // writable: true, 1004 | // enumerable: true, 1005 | // configurable: true 1006 | // }); 1007 | 1008 | // For best browser support, use the following: 1009 | A[k] = mappedValue; 1010 | } 1011 | // d. Increase k by 1. 1012 | k++; 1013 | } 1014 | 1015 | // 9. return A 1016 | return A; 1017 | }, 1018 | }); 1019 | } 1020 | 1021 | /** 1022 | * Array.prototype.pop() 1023 | * version 0.0.0 1024 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1025 | * Basic support 1 1 5.5 (Yes) (Yes) ? 1026 | * ------------------------------------------------------------------------------- 1027 | */ 1028 | 1029 | /** 1030 | * Array.prototype.push() 1031 | * version 0.0.0 1032 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1033 | * Basic support 1 1 5.5 (Yes) (Yes) ? 1034 | * ------------------------------------------------------------------------------- 1035 | */ 1036 | 1037 | /** 1038 | * Array.prototype.reduce() 1039 | * version 0.0.0 1040 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1041 | * Basic support (Yes) 3 9 10.5 4 ? 1042 | * ------------------------------------------------------------------------------- 1043 | */ 1044 | if (!Array.prototype.reduce) { 1045 | Object.defineProperty(Array.prototype, 'reduce', { 1046 | configurable: true, 1047 | writable: true, 1048 | value: function (callback /*, initialValue*/) { 1049 | if (this === null) { 1050 | throw new TypeError( 1051 | 'Array.prototype.reduce ' + 'called on null or undefined' 1052 | ); 1053 | } 1054 | if (typeof callback !== 'function') { 1055 | throw new TypeError(callback + ' is not a function'); 1056 | } 1057 | 1058 | // 1. Let O be ? ToObject(this value). 1059 | var o = Object(this); 1060 | 1061 | // 2. Let len be ? ToLength(? Get(O, "length")). 1062 | var len = o.length >>> 0; 1063 | 1064 | // Steps 3, 4, 5, 6, 7 1065 | var k = 0; 1066 | var value; 1067 | 1068 | if (arguments.length >= 2) { 1069 | value = arguments[1]; 1070 | } else { 1071 | while (k < len && !(k in o)) { 1072 | k++; 1073 | } 1074 | 1075 | // 3. If len is 0 and initialValue is not present, 1076 | // throw a TypeError exception. 1077 | if (k >= len) { 1078 | throw new TypeError( 1079 | 'Reduce of empty array ' + 'with no initial value' 1080 | ); 1081 | } 1082 | value = o[k++]; 1083 | } 1084 | 1085 | // 8. Repeat, while k < len 1086 | while (k < len) { 1087 | // a. Let Pk be ! ToString(k). 1088 | // b. Let kPresent be ? HasProperty(O, Pk). 1089 | // c. If kPresent is true, then 1090 | // i. Let kValue be ? Get(O, Pk). 1091 | // ii. Let accumulator be ? Call( 1092 | // callbackfn, undefined, 1093 | // « accumulator, kValue, k, O »). 1094 | if (k in o) { 1095 | value = callback(value, o[k], k, o); 1096 | } 1097 | 1098 | // d. Increase k by 1. 1099 | k++; 1100 | } 1101 | 1102 | // 9. Return accumulator. 1103 | return value; 1104 | }, 1105 | }); 1106 | } 1107 | 1108 | /** 1109 | * Array.prototype.reduceRight() 1110 | * version 0.0.0 1111 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1112 | * Basic support (Yes) 3 9 10.5 4 ? 1113 | * ------------------------------------------------------------------------------- 1114 | */ 1115 | if ('function' !== typeof Array.prototype.reduceRight) { 1116 | Object.defineProperty(Array.prototype, 'reduceRight', { 1117 | configurable: true, 1118 | writable: true, 1119 | value: function (callback /*, initialValue*/) { 1120 | if (null === this || 'undefined' === typeof this) { 1121 | throw new TypeError( 1122 | 'Array.prototype.reduce called on null or undefined' 1123 | ); 1124 | } 1125 | if ('function' !== typeof callback) { 1126 | throw new TypeError(callback + ' is not a function'); 1127 | } 1128 | var t = Object(this), 1129 | len = t.length >>> 0, 1130 | k = len - 1, 1131 | value; 1132 | if (arguments.length >= 2) { 1133 | value = arguments[1]; 1134 | } else { 1135 | while (k >= 0 && !(k in t)) { 1136 | k--; 1137 | } 1138 | if (k < 0) { 1139 | throw new TypeError('Reduce of empty array with no initial value'); 1140 | } 1141 | value = t[k--]; 1142 | } 1143 | for (; k >= 0; k--) { 1144 | if (k in t) { 1145 | value = callback(value, t[k], k, t); 1146 | } 1147 | } 1148 | return value; 1149 | }, 1150 | }); 1151 | } 1152 | 1153 | /** 1154 | * Array.prototype.reverse() 1155 | * version 0.0.0 1156 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1157 | * Basic support 1 1 5.5 (Yes) (Yes) (Yes) 1158 | * ------------------------------------------------------------------------------- 1159 | */ 1160 | 1161 | /** 1162 | * Array.prototype.shift() 1163 | * version 0.0.0 1164 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1165 | * Basic support 1 1 5.5 (Yes) (Yes) (Yes) 1166 | * ------------------------------------------------------------------------------- 1167 | */ 1168 | 1169 | /** 1170 | * Array.prototype.slice() 1171 | * version 0.0.0 1172 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1173 | * Basic support 1 1 5.5 (Yes) (Yes) (Yes) 1174 | * ------------------------------------------------------------------------------- 1175 | */ 1176 | 1177 | /** 1178 | * Array.prototype.some() 1179 | * version 0.0.0 1180 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1181 | * Basic support 1 1.5 9 (Yes) (Yes) ? 1182 | * ------------------------------------------------------------------------------- 1183 | */ 1184 | if (!Array.prototype.some) { 1185 | Object.defineProperty(Array.prototype, 'some', { 1186 | configurable: true, 1187 | writable: true, 1188 | value: function (fun /*, thisArg*/) { 1189 | if (this == null) { 1190 | throw new TypeError('Array.prototype.some called on null or undefined'); 1191 | } 1192 | 1193 | if (typeof fun !== 'function') { 1194 | throw new TypeError(); 1195 | } 1196 | 1197 | var t = Object(this); 1198 | var len = t.length >>> 0; 1199 | 1200 | var thisArg = arguments.length >= 2 ? arguments[1] : void 0; 1201 | for (var i = 0; i < len; i++) { 1202 | if (i in t && fun.call(thisArg, t[i], i, t)) { 1203 | return true; 1204 | } 1205 | } 1206 | 1207 | return false; 1208 | }, 1209 | }); 1210 | } 1211 | 1212 | /** 1213 | * Array.prototype.sort() 1214 | * version 0.0.0 1215 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1216 | * Basic support 1 1 5.5 (Yes) (Yes) (Yes) 1217 | * ------------------------------------------------------------------------------- 1218 | */ 1219 | 1220 | /** 1221 | * Array.prototype.splice() 1222 | * version 0.0.0 1223 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1224 | * Basic support 1 1 5.5 (Yes) (Yes) (Yes) 1225 | * ------------------------------------------------------------------------------- 1226 | */ 1227 | 1228 | /** 1229 | * Array.prototype.toLocaleString() 1230 | * version 0.0.0 1231 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1232 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 1233 | * ------------------------------------------------------------------------------- 1234 | */ 1235 | if (!Array.prototype.toLocaleString) { 1236 | Object.defineProperty(Array.prototype, 'toLocaleString', { 1237 | configurable: true, 1238 | writable: true, 1239 | value: function (locales, options) { 1240 | // 1. Let O be ? ToObject(this value). 1241 | if (this == null) { 1242 | throw new TypeError('"this" is null or not defined'); 1243 | } 1244 | 1245 | var a = Object(this); 1246 | 1247 | // 2. Let len be ? ToLength(? Get(A, "length")). 1248 | var len = a.length >>> 0; 1249 | 1250 | // 3. Let separator be the String value for the 1251 | // list-separator String appropriate for the 1252 | // host environment's current locale (this is 1253 | // derived in an implementation-defined way). 1254 | // NOTE: In this case, we will use a comma 1255 | var separator = ','; 1256 | 1257 | // 4. If len is zero, return the empty String. 1258 | if (len === 0) { 1259 | return ''; 1260 | } 1261 | 1262 | // 5. Let firstElement be ? Get(A, "0"). 1263 | var firstElement = a[0]; 1264 | // 6. If firstElement is undefined or null, then 1265 | // a.Let R be the empty String. 1266 | // 7. Else, 1267 | // a. Let R be ? 1268 | // ToString(? 1269 | // Invoke( 1270 | // firstElement, 1271 | // "toLocaleString", 1272 | // « locales, options » 1273 | // ) 1274 | // ) 1275 | var r = 1276 | firstElement == null 1277 | ? '' 1278 | : firstElement.toLocaleString(locales, options); 1279 | 1280 | // 8. Let k be 1. 1281 | var k = 1; 1282 | 1283 | // 9. Repeat, while k < len 1284 | while (k < len) { 1285 | // a. Let S be a String value produced by 1286 | // concatenating R and separator. 1287 | var s = r + separator; 1288 | 1289 | // b. Let nextElement be ? Get(A, ToString(k)). 1290 | var nextElement = a[k]; 1291 | 1292 | // c. If nextElement is undefined or null, then 1293 | // i. Let R be the empty String. 1294 | // d. Else, 1295 | // i. Let R be ? 1296 | // ToString(? 1297 | // Invoke( 1298 | // nextElement, 1299 | // "toLocaleString", 1300 | // « locales, options » 1301 | // ) 1302 | // ) 1303 | r = 1304 | nextElement == null 1305 | ? '' 1306 | : nextElement.toLocaleString(locales, options); 1307 | 1308 | // e. Let R be a String value produced by 1309 | // concatenating S and R. 1310 | r = s + r; 1311 | 1312 | // f. Increase k by 1. 1313 | k++; 1314 | } 1315 | 1316 | // 10. Return R. 1317 | return r; 1318 | }, 1319 | }); 1320 | } 1321 | 1322 | /** 1323 | * Array.prototype.toString() 1324 | * version 0.0.0 1325 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1326 | * Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) 1327 | * ------------------------------------------------------------------------------- 1328 | */ 1329 | 1330 | /** 1331 | * Array.prototype.unshift() 1332 | * version 0.0.0 1333 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1334 | * Basic support 1 1 5.5 (Yes) (Yes) ? 1335 | * ------------------------------------------------------------------------------- 1336 | */ 1337 | 1338 | /** 1339 | * Array.prototype.values() 1340 | * version 0.0.0 1341 | * Feature Chrome Firefox Internet Explorer Opera Safari Edge 1342 | * Basic support (No) (No) (No) (No) 9 (Yes) 1343 | * ------------------------------------------------------------------------------- 1344 | */ 1345 | if (!Array.prototype.values) { 1346 | Array.prototype.values = function () { 1347 | function Iterator() { } 1348 | 1349 | Iterator.prototype.next = function () { 1350 | if (index > selfThis.length - 1) { 1351 | done = true; 1352 | } 1353 | if (done) { 1354 | return { value: undefined, done: true }; 1355 | } 1356 | return { value: selfThis[index++], done: false }; 1357 | }; 1358 | 1359 | var selfThis = this; 1360 | var index = 0; 1361 | var done; 1362 | 1363 | return new Iterator(); 1364 | }; 1365 | } 1366 | --------------------------------------------------------------------------------