Skip to content

Commit

Permalink
Add Array.fill polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharrtell committed Nov 26, 2016
1 parent 3890a08 commit 223d1ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "topolis",
"description": "JavaScript topology representation and manipulation",
"version": "0.1.0",
"version": "0.1.1",
"author": "Björn Harrtell <bjorn@wololo.org>",
"keywords": [
"JSTS",
Expand Down
36 changes: 36 additions & 0 deletions src/Array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Polyfill service v3.13.0
* For detailed credits and licence information see http://github.com/financial-times/polyfill-service
*
* - Array.prototype.fill, License: CC0 */

if (!('fill' in Array.prototype)) {
Object.defineProperty(Array.prototype, 'fill', {
configurable: true,
value: function fill (value) {
if (this === undefined || this === null) {
throw new TypeError(this + ' is not an object')
}

var arrayLike = Object(this)

var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0

var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0

relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length)

var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length

relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length)

while (relativeStart < relativeEnd) {
arrayLike[relativeStart] = value

++relativeStart
}

return arrayLike
},
writable: true
})
}
2 changes: 2 additions & 0 deletions src/topolis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @module
*/

import './Array'

export {
/**
* @type {module:topo.createTopology}
Expand Down

0 comments on commit 223d1ba

Please sign in to comment.