prc b6c02717e6 Upload complete no-internet building environment. | 1 år sedan | |
---|---|---|
.. | ||
.github | 1 år sedan | |
aos | 1 år sedan | |
test | 1 år sedan | |
.eslintrc | 1 år sedan | |
.nycrc | 1 år sedan | |
CHANGELOG.md | 1 år sedan | |
LICENSE | 1 år sedan | |
README.md | 1 år sedan | |
auto.js | 1 år sedan | |
implementation.js | 1 år sedan | |
index.js | 1 år sedan | |
package.json | 1 år sedan | |
polyfill.js | 1 år sedan | |
shim.js | 1 år sedan |
An ESnext spec-compliant Object.groupBy
shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.
npm install --save object.groupby
var groupBy = require('object.groupby');
var assert = require('assert');
var arr = [0, 1, 2, 3, 4, 5];
var parity = function (x) { return x % 2 === 0 ? 'even' : 'odd'; };
var results = groupBy(arr, function (x, i) {
assert.equal(x, arr[i]);
return parity(x);
});
assert.deepEqual(results, {
__proto__: null,
even: [0, 2, 4],
odd: [1, 3, 5],
});
var groupBy = require('object.groupby');
var assert = require('assert');
/* when Object.groupBy is not present */
delete Object.groupBy;
var shimmed = groupBy.shim();
assert.equal(shimmed, groupBy.getPolyfill());
assert.deepEqual(Object.groupBy(arr, parity), groupBy(arr, parity));
var groupBy = require('object.groupby');
var assert = require('assert');
/* when Array#group is present */
var shimmed = groupBy.shim();
assert.equal(shimmed, Object.groupBy);
assert.deepEqual(Object.groupBy(arr, parity), groupBy(arr, parity));
Simply clone the repo, npm install
, and run npm test