Installation
A javascript polyfill library for es6 API such as findIndex, Array.from, etc.
NPM
# latest stable$ npm install es6-polyfill
Explanation of Different Builds
In the dist/
directory you will find different builds of cookie-box. Here's an overview of the difference between them:
UMD | CommonJS | ES Module | |
---|---|---|---|
Full | es6-polyfill.umd.js | es6-polyfill.cjs.js | es6-polyfill.esm.js |
Quick Start
;_; // => ['f', 'o', 'o']
API
Object
#keys(obj)
-
Arguments
- {Object} obj
-
Returns
- {Array}
-
Usage
Returns an array of a given object's own enumerable properties.
;
#assign(target, ...sources)
-
Arguments
- {Object} target
- {Object} ...sources
-
Returns
- {Object}
-
Usage
Return the target object that copy the values of all enumerable own properties from one or more source objects.
;; // => { a: 1, b: 2, c: 3 }
Function
#bind(fn, thisArg)
-
Arguments
- {Function} fn
- {Object} thisArg
-
Returns
- {Function}
-
Usage
Return a new function that, when called, has its
this
keyword set to the provided value.;const module =x: 81{ return thisx; };const retrieveX = modulegetX;retrieveX); // => 81
Array
#from(arrayLike [ , mapfn [ , thisArg ] ])
-
Arguments
- {Object} arrayLike
- {Function} mapFn
- {Object} thisArg
-
Returns
- {Array}
-
Usage
Return a new Array from a group of arrayLike arguments.
;; // => ['f', 'o', 'o']; // => [2, 4, 6]; // => [0, 1, 2, 3, 4]
#isArray(value)
-
Arguments
- {Object} value
-
Returns
- {Boolean}
-
Usage
Return true when the value is an Array, and return false when the value is not an Array.
;; // => false; // => false; // => false; // => true
#find(array, predicate)
-
Arguments
- {Array} array
- {Function} predicate
-
Returns
- {Any}
-
Usage
Return the value of the first element in the array that satisfies the provided testing function, otherwise return undefined.
;; // => 130); // => { name: 'cherries', quantity: 5 }; // => undefined
#findIndex(array, predicate)
-
Arguments
- {Array} array
- {Function} predicate
-
Returns
- {Number}
-
Usage
Return the index of the first element in the array that satisfies the provided testing function, otherwise return -1.
;const isPrime = {let start = 2;while start <= Mathif element % start++ < 1 return false;return element > 1;};; // => 2; // => -1
#indexOf(array, vMember [ , nStartFrom ])
-
Arguments
- {Array} array
- {Any} vMember
- {Number} nStartFrom
-
Returns
- {Number}
-
Usage
Returns the first index at which a given element can be found in the array, otherwise return -1.
;; // => 1; // => 2; // => -1; // => -1
#reverse(array)
-
Arguments
- {Array} array
-
Returns
- {Array}
-
Usage
Return the reversed array from the original, and the initial array will also modified.
;// => [2, 6, 4, 8]
String
#includes(string, search, start)
-
Arguments
- {String} string
- {String} string
- {Number} start
-
Returns
- {Boolean}
-
Usage
Return true when search is present and return false if not.
;; // => false; // => false; // => true; // => true
Running tests
$ npm run test # mocha test$ npm run lint # eslint
Authors
weiting-zhang
LICENSE
MIT