Comparing version 2.7.0 to 2.8.0
200
lib/dodo.js
@@ -13,2 +13,4 @@ 'use strict'; | ||
exports.arrayToDodo = arrayToDodo; | ||
var _invariant = require('invariant'); | ||
@@ -46,16 +48,6 @@ | ||
var action = Symbol('action'); | ||
var currentIndex = Symbol('currentIndex'); | ||
var names = Symbol('names'); | ||
var meta = Symbol('meta'); | ||
var dispatchReduce = Symbol('dispatchReduce'); | ||
var noActions = []; | ||
var Arrays = new WeakMap(); | ||
var Metadata = new WeakMap(); | ||
var needSlowCase = function needSlowCase(a) { | ||
return a.toString().includes('new Take') || a.toString().includes('new Drop'); | ||
}; | ||
var Dodo = function () { | ||
@@ -70,11 +62,7 @@ function Dodo(array, index) { | ||
(0, _invariant2.default)(Array.isArray(array), 'new Dodo(arr, index) - arr is required'); | ||
(0, _invariant2.default)(index, 'new Dodo(arr, index) - index is missing'); | ||
(0, _invariant2.default)(Object.keys(index).length == array[0].length, 'new Dodo(arr, index) - index length (' + Object.keys(index).length + ') != array[0].length (' + array[0].length + ')'); | ||
(0, _invariant2.default)(index === false || actions !== noActions || Object.keys(index).length == array[0].length, 'new Dodo(arr, index) - index length (' + Object.keys(index).length + ') != array[0].length (' + array[0].length + ')'); | ||
this.index = index; | ||
this.actions = actions; | ||
Arrays.set(this, array); | ||
if (!Metadata.has(array)) Metadata.set(array, { | ||
columns: new Set(Object.keys(index)) | ||
}); | ||
this.actions = actions; | ||
this.index = index; | ||
} | ||
@@ -90,3 +78,3 @@ | ||
value: function toArray() { | ||
if (this.actions.length) return (this.actions.some(needSlowCase) ? _transducers.transduce : _helpers.transduceNoBreak)(Arrays.get(this), (0, _helpers.compose)(this.actions), _helpers.arrayReducer, []);else return Arrays.get(this); | ||
if (this.actions != noActions) return (this.actions.some(_helpers.needSlowCase) ? _transducers.transduce : _helpers.transduceNoBreak)(Arrays.get(this), (0, _helpers.compose)(this.actions), _helpers.arrayReducer, []);else return Arrays.get(this); | ||
} | ||
@@ -99,9 +87,7 @@ }, { | ||
}, { | ||
key: action, | ||
value: function value(action) { | ||
if (action) { | ||
return new Dodo(Arrays.get(this), this.index, [].concat(_toConsumableArray(this.actions), [action])); | ||
} else { | ||
return new Dodo(Arrays.get(this), this.index, [].concat(_toConsumableArray(this.actions))); | ||
} | ||
key: 'transform', | ||
value: function transform(transformer) { | ||
var index = arguments.length <= 1 || arguments[1] === undefined ? this.index : arguments[1]; | ||
return new Dodo(Arrays.get(this), index, [].concat(_toConsumableArray(this.actions), [transformer])); | ||
} | ||
@@ -114,9 +100,7 @@ }, { | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#filter(fn) — fn not a function'); | ||
if (this[names].length == 1) { | ||
return this[action]((0, _transducers.filter)(fn)); | ||
} else { | ||
if (this.index) { | ||
var _ret = function () { | ||
var I = _this[currentIndex]; | ||
var I = _this.index; | ||
return { | ||
v: _this[action]((0, _transducers.filter)(function (row) { | ||
v: _this.transform((0, _transducers.filter)(function (row) { | ||
return fn(row, I); | ||
@@ -128,2 +112,4 @@ })) | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else { | ||
return this.transform((0, _transducers.filter)(fn)); | ||
} | ||
@@ -134,6 +120,8 @@ } | ||
value: function filterBy(name, fn) { | ||
(0, _invariant2.default)(name, 'Dodo#filterBy(name, fn) - col is required'); | ||
(0, _invariant2.default)(this.index, 'Dodo#filterBy(name, fn) — only available on indexed dodos'); | ||
(0, _invariant2.default)(name, 'Dodo#filterBy(name, fn) - name is required'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#filterBy(name, fn) - fn not a function'); | ||
var col = this[currentIndex][name]; | ||
return this[action]((0, _transducers.filter)(function (row) { | ||
var col = this.index[name]; | ||
(0, _invariant2.default)(col != null, 'Dodo#col(name) — name ' + name + ' not in index'); | ||
return this.transform((0, _transducers.filter)(function (row) { | ||
return fn(row[col]); | ||
@@ -148,9 +136,7 @@ })); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#map(fn) — fn not a function'); | ||
if (this[names].length == 1) { | ||
return this[action]((0, _transducers.map)(fn)); | ||
} else { | ||
if (this.index) { | ||
var _ret2 = function () { | ||
var I = _this2[currentIndex]; | ||
var I = _this2.index; | ||
return { | ||
v: _this2[action]((0, _transducers.map)(function (row) { | ||
v: _this2.transform((0, _transducers.map)(function (row) { | ||
return fn(row, I); | ||
@@ -162,2 +148,4 @@ })) | ||
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v; | ||
} else { | ||
return this.transform((0, _transducers.map)(fn)); | ||
} | ||
@@ -168,11 +156,11 @@ } | ||
value: function col(name) { | ||
(0, _invariant2.default)(name, 'Dodo#filterBy(name, fn) - col is required'); | ||
(0, _invariant2.default)(this[meta].columns.has(name), 'Dodo#col(name) — name ' + name + ' not in index'); | ||
var col = this[currentIndex][name]; | ||
var fn = (0, _transducers.map)(function (row) { | ||
(0, _invariant2.default)(this.index, 'Dodo#col(name) — only available on indexed dodos'); | ||
(0, _invariant2.default)(name, 'Dodo#col(name) - name is required'); | ||
var col = this.index[name]; | ||
(0, _invariant2.default)(col != null, 'Dodo#col(name) — name ' + name + ' not in index'); | ||
return this.transform((0, _transducers.map)(function (row) { | ||
return row[col]; | ||
}); | ||
fn.I = (0, _helpers.arrayToIndex)([name]); | ||
fn.singular = true; | ||
return this[action](fn); | ||
}), false); | ||
} | ||
@@ -188,17 +176,17 @@ }, { | ||
(0, _invariant2.default)(this.index, 'Dodo#cols(...names) — only available on indexed dodos'); | ||
names = names.length ? (0, _flatten2.default)(names) : undefined; | ||
(0, _invariant2.default)(names, 'Dodo#cols(names) - names is required'); | ||
names.forEach(function (n) { | ||
return (0, _invariant2.default)(_this3[meta].columns.has(n), 'Dodo#cols(names) - name ' + n + ' not in index'); | ||
}); | ||
(0, _invariant2.default)(names, 'Dodo#cols(...names) - names is required'); | ||
var indices = names.map(function (name) { | ||
return _this3[currentIndex][name]; | ||
return _this3.index[name]; | ||
}); | ||
var inner = new Function('row', '\n return [' + indices.map(function (i) { | ||
indices.forEach(function (i) { | ||
return (0, _invariant2.default)(i != null, 'Dodo#cols(...names) - name ' + _this3.columns[i] + ' not in index'); | ||
}); | ||
var fn = (0, _transducers.map)(new Function('row', 'return [' + indices.map(function (i) { | ||
return 'row[' + i + ']'; | ||
}).join(',') + ']\n '); | ||
var fn = (0, _transducers.map)(inner); | ||
fn.I = (0, _helpers.arrayToIndex)(names); | ||
return this[action](fn); | ||
}).join(',') + ']')); | ||
return this.transform(fn, names); | ||
} | ||
@@ -209,5 +197,5 @@ }, { | ||
(0, _invariant2.default)(Number.isFinite(amount), 'Dodo#skip(amount) - amount must be a number'); | ||
if (amount === 0) return this[action](); | ||
(0, _invariant2.default)(amount > 0, 'Dodo#skip(amount) — amount smaller than 0'); | ||
return this[action]((0, _transducers.drop)(amount)); | ||
(0, _invariant2.default)(amount >= 0, 'Dodo#skip(amount) — amount smaller than 0'); | ||
if (amount === 0) return this;else return this.transform((0, _transducers.drop)(amount)); | ||
} | ||
@@ -219,12 +207,6 @@ }, { | ||
(0, _invariant2.default)(amount >= 0, 'Dodo#take(amount) — amount smaller than 0'); | ||
return this[action]((0, _transducers.take)(amount)); | ||
return this.transform((0, _transducers.take)(amount)); | ||
} | ||
}, { | ||
key: dispatchReduce, | ||
value: function value(fn, initFactory, final) { | ||
if (this.actions.find(function (a) { | ||
return a.singular; | ||
})) return this.reduce(fn, initFactory(), final);else return this.reduceEach(fn, initFactory, final); | ||
} | ||
}, { | ||
key: 'reduce', | ||
@@ -239,3 +221,4 @@ value: function reduce(fn, init) { | ||
(0, _invariant2.default)((0, _helpers.isfunc)(final), 'Dodo#reduce(fn, init, final) — final not a function'); | ||
return (this.actions.some(needSlowCase) ? _transducers.transduce : _helpers.transduceNoBreak)(Arrays.get(this), (0, _helpers.compose)(this.actions), (_ref = {}, _defineProperty(_ref, '@@transducer/step', fn), _defineProperty(_ref, '@@transducer/result', final), _ref), init); | ||
return (this.actions.some(_helpers.needSlowCase) ? _transducers.transduce : _helpers.transduceNoBreak)(Arrays.get(this), (0, _helpers.compose)(this.actions), (_ref = {}, _defineProperty(_ref, '@@transducer/step', fn), _defineProperty(_ref, '@@transducer/result', final), _ref), init); | ||
} | ||
@@ -247,7 +230,8 @@ }, { | ||
(0, _invariant2.default)((0, _helpers.isfunc)(initFactory), 'Dodo#reduceEach(fn, initFactory, final) - initFactory not a function'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#reduceEach(fn, init, final) — fn not a function'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(final), 'Dodo#reduceEach(fn, init, final) — final not a function'); | ||
(0, _invariant2.default)(this.index, 'Dodo#reduceEach(fn, initFactory, final?) - only available on indexed dodos'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#reduceEach(fn, initFactory, final?) — fn not a function'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(initFactory), 'Dodo#reduceEach(fn, initFactory, final?) - initFactory not a function'); | ||
(0, _invariant2.default)((0, _helpers.isfunc)(final), 'Dodo#reduceEach(fn, ininitFactory, final?) — final not a function'); | ||
var _unzip = (0, _unzip4.default)(this[names].map(function () { | ||
var _unzip = (0, _unzip4.default)(this.columns.map(function () { | ||
return [fn, initFactory(), final]; | ||
@@ -262,3 +246,3 @@ })); | ||
return (0, _zipObject2.default)(this[names], this.reduce((0, _helpers.combineReducers)(fns, true), inits, (0, _helpers.spread)(finals))); | ||
return (0, _zipObject2.default)(this.columns, this.reduce((0, _helpers.combineReducers)(fns, true), inits, (0, _helpers.spread)(finals))); | ||
} | ||
@@ -287,3 +271,3 @@ }, { | ||
return this[dispatchReduce]((0, _helpers.combineReducers)(fns), function () { | ||
return _helpers.dispatchReduce.call(this, (0, _helpers.combineReducers)(fns), function () { | ||
return inits.map(function (i) { | ||
@@ -297,3 +281,3 @@ return i(); | ||
value: function count() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.count)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.count))); | ||
} | ||
@@ -303,3 +287,3 @@ }, { | ||
value: function sum() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.sum)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.sum))); | ||
} | ||
@@ -309,3 +293,3 @@ }, { | ||
value: function min() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.min)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.min))); | ||
} | ||
@@ -315,3 +299,3 @@ }, { | ||
value: function max() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.max)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.max))); | ||
} | ||
@@ -321,3 +305,3 @@ }, { | ||
value: function countUniq() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.countUniq)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.countUniq))); | ||
} | ||
@@ -327,3 +311,3 @@ }, { | ||
value: function mean() { | ||
return this[dispatchReduce].apply(this, _toConsumableArray(_helpers.REDUCERS.mean)); | ||
return _helpers.dispatchReduce.call.apply(_helpers.dispatchReduce, [this].concat(_toConsumableArray(_helpers.REDUCERS.mean))); | ||
} | ||
@@ -333,15 +317,17 @@ }, { | ||
value: function groupBy(name, fn) { | ||
(0, _invariant2.default)(name, 'Dodo#groupBy(name, fn) - name is required'); | ||
(0, _invariant2.default)(this[meta].columns.has(name), 'Dodo#group(name) — name ' + name + ' not in index'); | ||
var _this4 = this; | ||
var map = new Map(); | ||
var grouper = (0, _helpers.createGrouper)(map, fn, this[currentIndex][name]); | ||
var array = this.toArray(); | ||
var len = array.length; | ||
var i = -1; | ||
while (++i < len) { | ||
grouper(array[i]); | ||
if ((0, _helpers.isfunc)(name)) { | ||
fn = name; | ||
name = undefined; | ||
} | ||
map.forEach(arrayToDodo(this[currentIndex])); | ||
return Flock(map); | ||
(0, _invariant2.default)(this.index ? name : !name, 'Dodo#groupBy(name, fn?) — name is required on indexed dodos'); | ||
(0, _invariant2.default)(!name || this.columns.includes(name), 'Dodo#groupBy(name?, fn?) — name ' + name + ' not in index'); | ||
(0, _invariant2.default)(!fn || (0, _helpers.isfunc)(fn), 'Dodo#groupBy(name?, fn?) — fn not a function'); | ||
var grouper = (0, _helpers.createGrouper)(fn, name ? this.index[name] : name); | ||
var toDodos = function toDodos(map) { | ||
return map.forEach(arrayToDodo(_this4.index)), map; | ||
}; | ||
return Flock(this.reduce(grouper, new Map(), toDodos)); | ||
} | ||
@@ -352,24 +338,11 @@ }, { | ||
(0, _invariant2.default)((0, _helpers.isfunc)(fn), 'Dodo#flock(fn) — fn not a function'); | ||
return Flock(fn(this)); | ||
return Flock(fn.call(this, this)); | ||
} | ||
}, { | ||
key: meta, | ||
key: 'columns', | ||
get: function get() { | ||
return Metadata.get(Arrays.get(this)); | ||
} | ||
}, { | ||
key: currentIndex, | ||
get: function get() { | ||
var lastMapWithIndex = this.actions.filter(function (act) { | ||
return !!act.I; | ||
}).slice(-1); | ||
var _this5 = this; | ||
if (lastMapWithIndex.length) return lastMapWithIndex[0].I;else return this.index; | ||
} | ||
}, { | ||
key: names, | ||
get: function get() { | ||
var I = this[currentIndex]; | ||
return Object.keys(I).sort(function (a, b) { | ||
return I[a] - I[b]; | ||
return Object.keys(this.index).sort(function (a, b) { | ||
return _this5.index[a] - _this5.index[b]; | ||
}); | ||
@@ -388,7 +361,5 @@ } | ||
exports.default = Dodo; | ||
function arrayToDodo(Index) { | ||
function arrayToDodo(index) { | ||
return function (array, key, map) { | ||
map.set(key, new Dodo(array, Index)); | ||
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XMuZW50cmllcygpXVxuICBjb25zdCBsZW4gPSB0aGlzLnNpemVcbiAgbGV0IGkgPSAtMVxuICB3aGlsZSAoKytpIDwgbGVuKSB7XG4gICAgbGV0IGVudHJ5ID0gZW50cmllc1tpXVxuICAgIGVudHJpZXNbaV0gPSBmbihlbnRyeVsxXSwgZW50cnlbMF0sIHRoaXMpXG4gIH1cbiAgcmV0dXJuIGVudHJpZXNcbn1cbiJdfQ== |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.arrayToIndex = exports.isfunc = exports.REDUCERS = exports.arrayReducer = exports.identity = undefined; | ||
exports.needSlowCase = exports.arrayToIndex = exports.isfunc = exports.REDUCERS = exports.arrayReducer = exports.identity = undefined; | ||
@@ -18,2 +18,3 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.createGrouper = createGrouper; | ||
exports.dispatchReduce = dispatchReduce; | ||
@@ -137,13 +138,31 @@ var _zipObject = require('lodash/zipObject'); | ||
function createGrouper(map, fn, col) { | ||
function createGrouper(fn, col) { | ||
if (fn) { | ||
return function (row) { | ||
var key = fn(row[col]); | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
}; | ||
if (col == undefined) { | ||
return function (map, row) { | ||
var key = fn(row); | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
return map; | ||
}; | ||
} else { | ||
return function (map, row) { | ||
var key = fn(row[col]); | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
return map; | ||
}; | ||
} | ||
} else { | ||
return function (row) { | ||
var key = row[col]; | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
}; | ||
if (col == undefined) { | ||
return function (map, row) { | ||
var key = row; | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
return map; | ||
}; | ||
} else { | ||
return function (map, row) { | ||
var key = row[col]; | ||
map.has(key) ? map.get(key).push(row) : map.set(key, [row]); | ||
return map; | ||
}; | ||
} | ||
} | ||
@@ -155,4 +174,14 @@ } | ||
}; | ||
var arrayToIndex = exports.arrayToIndex = function arrayToIndex(arr) { | ||
return (0, _zipObject2.default)(arr, [].concat(_toConsumableArray(arr.keys()))); | ||
}; | ||
}; | ||
var needSlowCase = exports.needSlowCase = function needSlowCase(a) { | ||
return a.toString().includes('new Take') || a.toString().includes('new Drop'); | ||
}; | ||
function dispatchReduce(fn, initFactory, final) { | ||
if (this.index) return this.reduceEach(fn, initFactory, final);else return this.reduce(fn, initFactory(), final); | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9oZWxwZXJzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O1FBSWdCO1FBWUE7UUFvQkE7UUFXQTtRQXNDQTtRQStDQTs7QUFwSWhCOzs7Ozs7Ozs7O0FBRU8sSUFBTSw4QkFBVyxTQUFYLFFBQVc7U0FBSztDQUFMOztBQUVqQixTQUFTLE9BQVQsQ0FBaUIsS0FBakIsRUFBd0I7QUFDN0IsTUFBSSxNQUFNLE1BQU0sTUFBTixDQURtQjtBQUU3QixTQUFPLFVBQVMsQ0FBVCxFQUFZO0FBQ2pCLFFBQUksUUFBUSxDQUFSLENBRGE7QUFFakIsUUFBSSxJQUFJLEdBQUosQ0FGYTtBQUdqQixXQUFPLEdBQVAsRUFBWTtBQUNWLGNBQVEsTUFBTSxDQUFOLEVBQVMsS0FBVCxD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LCBjb2wpIHtcbiAgaWYgKGZuKSB7XG4gICAgaWYgKGNvbCA9PSB1bmRlZmluZWQpIHtcbiAgICAgIHJldHVybiBmdW5jdGlvbihtYXAsIHJvdykge1xuICAgICAgICBjb25zdCBrZXkgPSBmbihyb3cpXG4gICAgICAgIG1hcC5oYXMoa2V5KVxuICAgICAgICAgID8gbWFwLmdldChrZXkpLnB1c2gocm93KVxuICAgICAgICAgIDogbWFwLnNldChrZXksIFtyb3ddKVxuICAgICAgICByZXR1cm4gbWFwXG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIHJldHVybiBmdW5jdGlvbihtYXAsIHJvdykge1xuICAgICAgICBjb25zdCBrZXkgPSBmbihyb3dbY29sXSlcbiAgICAgICAgbWFwLmhhcyhrZXkpXG4gICAgICAgICAgPyBtYXAuZ2V0KGtleSkucHVzaChyb3cpXG4gICAgICAgICAgOiBtYXAuc2V0KGtleSwgW3Jvd10pXG4gICAgICAgIHJldHVybiBtYXBcbiAgICAgIH1cbiAgICB9XG4gIH0gZWxzZSB7XG4gICAgaWYgKGNvbCA9PSB1bmRlZmluZWQpIHtcbiAgICAgIHJldHVybiBmdW5jdGlvbihtYXAsIHJvdykge1xuICAgICAgICBjb25zdCBrZXkgPSByb3dcbiAgICAgICAgbWFwLmhhcyhrZXkpXG4gICAgICAgICAgPyBtYXAuZ2V0KGtleSkucHVzaChyb3cpXG4gICAgICAgICAgOiBtYXAuc2V0KGtleSwgW3Jvd10pXG4gICAgICAgIHJldHVybiBtYXBcbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgcmV0dXJuIGZ1bmN0aW9uKG1hcCwgcm93KSB7XG4gICAgICAgIGNvbnN0IGtleSA9IHJvd1tjb2xdXG4gICAgICAgIG1hcC5oYXMoa2V5KVxuICAgICAgICAgID8gbWFwLmdldChrZXkpLnB1c2gocm93KVxuICAgICAgICAgIDogbWFwLnNldChrZXksIFtyb3ddKVxuICAgICAgICByZXR1cm4gbWFwXG4gICAgICB9XG4gICAgfVxuICB9XG59XG5cbmV4cG9ydCBjb25zdCBpc2Z1bmMgPSBmbiA9PiBmbiAmJiB0eXBlb2YgZm4gPT0gJ2Z1bmN0aW9uJ1xuXG5leHBvcnQgY29uc3QgYXJyYXlUb0luZGV4ID0gYXJyID0+IHppcE9iamVjdChhcnIsIFsuLi5hcnIua2V5cygpXSlcblxuZXhwb3J0IGNvbnN0IG5lZWRTbG93Q2FzZSA9IGEgPT5cbiAgYS50b1N0cmluZygpLmluY2x1ZGVzKCduZXcgVGFrZScpIHx8IGEudG9TdHJpbmcoKS5pbmNsdWRlcygnbmV3IERyb3AnKVxuXG5leHBvcnQgZnVuY3Rpb24gZGlzcGF0Y2hSZWR1Y2UoZm4sIGluaXRGYWN0b3J5LCBmaW5hbCkge1xuICBpZiAodGhpcy5pbmRleClcbiAgICByZXR1cm4gdGhpcy5yZWR1Y2VFYWNoKGZuLCBpbml0RmFjdG9yeSwgZmluYWwpXG4gIGVsc2VcbiAgICByZXR1cm4gdGhpcy5yZWR1Y2UoZm4sIGluaXRGYWN0b3J5KCksIGZpbmFsKVxufVxuIl19 |
{ | ||
"name": "dodos", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "Pandas-inspired iterator-based data wrangling library for js", | ||
@@ -17,3 +17,3 @@ "main": "lib/dodo.js", | ||
"prepush": "npm test", | ||
"prepublish": "npm test && npm run clean && npm run build", | ||
"prepublish": "git pull origin master && npm test && npm run clean && npm run build", | ||
"postpublish": "git push origin master --no-verify" | ||
@@ -38,3 +38,3 @@ }, | ||
"ava": "~0.14.0", | ||
"babel-cli": "~6.6.5", | ||
"babel-cli": "~6.7.5", | ||
"babel-core": "~6.7.2", | ||
@@ -48,13 +48,13 @@ "babel-eslint": "~6.0.0", | ||
"d3-dsv": "~0.3.1", | ||
"eslint": "~2.7.0", | ||
"eslint": "~2.8.0", | ||
"husky": "~0.11.4", | ||
"npm-check": "~5.1.1", | ||
"nyc": "~6.2.1", | ||
"npm-check": "~5.2.1", | ||
"nyc": "~6.4.0", | ||
"rimraf": "~2.5.2", | ||
"table": "~3.7.8", | ||
"webpack": "~1.12.14" | ||
"webpack": "~1.13.0" | ||
}, | ||
"dependencies": { | ||
"invariant": "~2.2.1", | ||
"lodash": "~4.8.2", | ||
"lodash": "~4.11.0", | ||
"transducers.js": "~0.3.2" | ||
@@ -61,0 +61,0 @@ }, |
195
src/dodo.js
@@ -10,18 +10,10 @@ import invariant from 'invariant' | ||
identity, combineReducers, REDUCERS, spread, createGrouper, isfunc, | ||
arrayToIndex, compose, transduceNoBreak, arrayReducer | ||
arrayToIndex, compose, transduceNoBreak, arrayReducer, needSlowCase, | ||
dispatchReduce | ||
} from './helpers' | ||
const action = Symbol('action') | ||
const currentIndex = Symbol('currentIndex') | ||
const names = Symbol('names') | ||
const meta = Symbol('meta') | ||
const dispatchReduce = Symbol('dispatchReduce') | ||
const noActions = [] | ||
const Arrays = new WeakMap() | ||
const Metadata = new WeakMap() | ||
const needSlowCase = a => | ||
a.toString().includes('new Take') || a.toString().includes('new Drop') | ||
export default class Dodo { | ||
@@ -33,35 +25,18 @@ constructor(array, index, actions=noActions) { | ||
invariant(Array.isArray(array), `new Dodo(arr, index) - arr is required`) | ||
invariant(index , `new Dodo(arr, index) - index is missing`) | ||
invariant(Object.keys(index).length == array[0].length, | ||
invariant(index === false || actions !== noActions || Object.keys(index).length == array[0].length, | ||
`new Dodo(arr, index) - index length (${Object.keys(index).length}) != array[0].length (${array[0].length})`) | ||
this.index = index | ||
this.actions = actions | ||
Arrays.set(this, array) | ||
if (!Metadata.has(array)) | ||
Metadata.set(array, { | ||
columns: new Set(Object.keys(index)), | ||
}) | ||
this.actions = actions | ||
this.index = index | ||
} | ||
get [meta]() { return Metadata.get(Arrays.get(this)) } | ||
get [currentIndex]() { | ||
const lastMapWithIndex = this.actions.filter(act => !!act.I).slice(-1) | ||
if (lastMapWithIndex.length) | ||
return lastMapWithIndex[0].I | ||
else | ||
return this.index | ||
get columns() { | ||
return Object.keys(this.index).sort((a, b) => this.index[a] - this.index[b]) | ||
} | ||
get [names]() { | ||
const I = this[currentIndex] | ||
return Object.keys(I).sort((a, b) => I[a] - I[b]) | ||
} | ||
[Symbol.iterator]() { return this.toArray().values() } | ||
toArray() { | ||
if (this.actions.length) | ||
if (this.actions != noActions) | ||
return (this.actions.some(needSlowCase) ? transduce : transduceNoBreak)( | ||
@@ -81,10 +56,4 @@ Arrays.get(this), | ||
[action](action) { | ||
if (action) { | ||
return new Dodo( | ||
Arrays.get(this), this.index, [...this.actions, action]) | ||
} else { | ||
return new Dodo( | ||
Arrays.get(this), this.index, [...this.actions]) | ||
} | ||
transform(transformer, index=this.index) { | ||
return new Dodo(Arrays.get(this), index, [...this.actions, transformer]) | ||
} | ||
@@ -94,7 +63,7 @@ | ||
invariant(isfunc(fn), `Dodo#filter(fn) — fn not a function`) | ||
if (this[names].length == 1) { | ||
return this[action](filter(fn)) | ||
if (this.index) { | ||
const I = this.index | ||
return this.transform(filter(row => fn(row, I))) | ||
} else { | ||
const I = this[currentIndex] | ||
return this[action](filter(row => fn(row, I))) | ||
return this.transform(filter(fn)) | ||
} | ||
@@ -104,6 +73,8 @@ } | ||
filterBy(name, fn) { | ||
invariant(name, `Dodo#filterBy(name, fn) - col is required`) | ||
invariant(this.index, `Dodo#filterBy(name, fn) — only available on indexed dodos`) | ||
invariant(name, `Dodo#filterBy(name, fn) - name is required`) | ||
invariant(isfunc(fn), `Dodo#filterBy(name, fn) - fn not a function`) | ||
const col = this[currentIndex][name] | ||
return this[action]( filter(row => fn(row[col])) ) | ||
const col = this.index[name] | ||
invariant(col != null, `Dodo#col(name) — name ${name} not in index`) | ||
return this.transform( filter(row => fn(row[col])) ) | ||
} | ||
@@ -113,7 +84,7 @@ | ||
invariant(isfunc(fn), `Dodo#map(fn) — fn not a function`) | ||
if (this[names].length == 1) { | ||
return this[action](map(fn)) | ||
if (this.index) { | ||
const I = this.index | ||
return this.transform(map(row => fn(row, I))) | ||
} else { | ||
const I = this[currentIndex] | ||
return this[action](map(row => fn(row, I))) | ||
return this.transform(map(fn)) | ||
} | ||
@@ -123,25 +94,21 @@ } | ||
col(name) { | ||
invariant(name, `Dodo#filterBy(name, fn) - col is required`) | ||
invariant(this[meta].columns.has(name), | ||
`Dodo#col(name) — name ${name} not in index`) | ||
const col = this[currentIndex][name] | ||
const fn = map(row => row[col]) | ||
fn.I = arrayToIndex([name]) | ||
fn.singular = true | ||
return this[action](fn) | ||
invariant(this.index, `Dodo#col(name) — only available on indexed dodos`) | ||
invariant(name, `Dodo#col(name) - name is required`) | ||
const col = this.index[name] | ||
invariant(col != null, `Dodo#col(name) — name ${name} not in index`) | ||
return this.transform(map(row => row[col]), false) | ||
} | ||
cols(...names) { | ||
invariant(this.index, `Dodo#cols(...names) — only available on indexed dodos`) | ||
names = names.length ? flatten(names) : undefined | ||
invariant(names, `Dodo#cols(names) - names is required`) | ||
names.forEach(n => invariant(this[meta].columns.has(n), | ||
`Dodo#cols(names) - name ${n} not in index`)) | ||
invariant(names, `Dodo#cols(...names) - names is required`) | ||
const indices = names.map(name => this[currentIndex][name]) | ||
const inner = new Function('row', ` | ||
return [${indices.map(i => `row[${i}]`).join(',')}] | ||
`) | ||
const fn = map(inner) | ||
fn.I = arrayToIndex(names) | ||
return this[action](fn) | ||
const indices = names.map(name => this.index[name]) | ||
indices.forEach(i => invariant(i != null, `Dodo#cols(...names) - name ${this.columns[i]} not in index`)) | ||
const fn = map(new Function('row',`return [${indices.map(i => `row[${i}]`).join(',')}]`)) | ||
return this.transform(fn, names) | ||
} | ||
@@ -151,5 +118,8 @@ | ||
invariant(Number.isFinite(amount), `Dodo#skip(amount) - amount must be a number`) | ||
if (amount === 0) return this[action]() | ||
invariant(amount > 0, `Dodo#skip(amount) — amount smaller than 0`) | ||
return this[action](drop(amount)) | ||
invariant(amount >= 0, `Dodo#skip(amount) — amount smaller than 0`) | ||
if (amount === 0) | ||
return this | ||
else | ||
return this.transform(drop(amount)) | ||
} | ||
@@ -160,10 +130,4 @@ | ||
invariant(amount >= 0, `Dodo#take(amount) — amount smaller than 0`) | ||
return this[action](take(amount)) | ||
} | ||
[dispatchReduce](fn, initFactory, final) { | ||
if (this.actions.find(a => a.singular)) | ||
return this.reduce(fn, initFactory(), final) | ||
else | ||
return this.reduceEach(fn, initFactory, final) | ||
return this.transform(take(amount)) | ||
} | ||
@@ -174,4 +138,4 @@ | ||
invariant(isfunc(fn), `Dodo#reduce(fn, init, final) — fn not a function`) | ||
invariant(isfunc(final), | ||
`Dodo#reduce(fn, init, final) — final not a function`) | ||
invariant(isfunc(final), `Dodo#reduce(fn, init, final) — final not a function`) | ||
return (this.actions.some(needSlowCase) ? transduce : transduceNoBreak)( | ||
@@ -189,13 +153,10 @@ Arrays.get(this), | ||
reduceEach(fn, initFactory, final=identity) { | ||
invariant(isfunc(initFactory), | ||
`Dodo#reduceEach(fn, initFactory, final) - initFactory not a function`) | ||
invariant(isfunc(fn), | ||
`Dodo#reduceEach(fn, init, final) — fn not a function`) | ||
invariant(isfunc(final), | ||
`Dodo#reduceEach(fn, init, final) — final not a function`) | ||
const [fns, inits, finals] = unzip( | ||
this[names].map(() => [fn, initFactory(), final]) | ||
) | ||
invariant(this.index, `Dodo#reduceEach(fn, initFactory, final?) - only available on indexed dodos`) | ||
invariant(isfunc(fn), `Dodo#reduceEach(fn, initFactory, final?) — fn not a function`) | ||
invariant(isfunc(initFactory), `Dodo#reduceEach(fn, initFactory, final?) - initFactory not a function`) | ||
invariant(isfunc(final), `Dodo#reduceEach(fn, ininitFactory, final?) — final not a function`) | ||
const [fns, inits, finals] = unzip(this.columns.map(() => [fn, initFactory(), final])) | ||
return zipObject( | ||
this[names], | ||
this.columns, | ||
this.reduce(combineReducers(fns, true), inits, spread(finals)) | ||
@@ -206,8 +167,7 @@ ) | ||
stats(...methods) { | ||
invariant(methods && methods.length, | ||
`Dodo#stats(...methods) - at least one method is required`) | ||
methods.forEach(m => invariant(typeof m == 'string' && m in REDUCERS, | ||
`Dodo#stats(...methods) - method ${m} is not implemented`)) | ||
invariant(methods && methods.length, `Dodo#stats(...methods) - at least one method is required`) | ||
methods.forEach(m => invariant(typeof m == 'string' && m in REDUCERS, `Dodo#stats(...methods) - method ${m} is not implemented`)) | ||
const [fns, inits, finals] = zip(...methods.map(m => REDUCERS[m])) | ||
return this[dispatchReduce]( | ||
return dispatchReduce.call(this, | ||
combineReducers(fns), | ||
@@ -219,29 +179,26 @@ () => inits.map(i => i()), | ||
count() { return this[dispatchReduce](...REDUCERS.count) } | ||
count() { return dispatchReduce.call(this, ...REDUCERS.count) } | ||
sum() { return this[dispatchReduce](...REDUCERS.sum) } | ||
sum() { return dispatchReduce.call(this, ...REDUCERS.sum) } | ||
min() { return this[dispatchReduce](...REDUCERS.min) } | ||
min() { return dispatchReduce.call(this, ...REDUCERS.min) } | ||
max() { return this[dispatchReduce](...REDUCERS.max) } | ||
max() { return dispatchReduce.call(this, ...REDUCERS.max) } | ||
countUniq() { return this[dispatchReduce](...REDUCERS.countUniq) } | ||
countUniq() { return dispatchReduce.call(this, ...REDUCERS.countUniq) } | ||
mean() { return this[dispatchReduce](...REDUCERS.mean) } | ||
mean() { return dispatchReduce.call(this, ...REDUCERS.mean) } | ||
groupBy(name, fn) { | ||
invariant(name, `Dodo#groupBy(name, fn) - name is required`) | ||
invariant(this[meta].columns.has(name), | ||
`Dodo#group(name) — name ${name} not in index`) | ||
if (isfunc(name)) { | ||
fn = name | ||
name = undefined | ||
} | ||
invariant(this.index ? name : !name, `Dodo#groupBy(name, fn?) — name is required on indexed dodos` ) | ||
invariant(!name || this.columns.includes(name), `Dodo#groupBy(name?, fn?) — name ${name} not in index`) | ||
invariant(!fn || isfunc(fn), `Dodo#groupBy(name?, fn?) — fn not a function`) | ||
const map = new Map() | ||
const grouper = createGrouper(map, fn, this[currentIndex][name]) | ||
const array = this.toArray() | ||
const len = array.length | ||
let i = -1 | ||
while (++i < len) { | ||
grouper(array[i]) | ||
} | ||
map.forEach(arrayToDodo(this[currentIndex])) | ||
return Flock(map) | ||
const grouper = createGrouper(fn, name ? this.index[name] : name) | ||
const toDodos = map => (map.forEach(arrayToDodo(this.index)), map) | ||
return Flock(this.reduce(grouper, new Map(), toDodos)) | ||
} | ||
@@ -251,9 +208,9 @@ | ||
invariant(isfunc(fn), `Dodo#flock(fn) — fn not a function`) | ||
return Flock(fn(this)) | ||
return Flock(fn.call(this, this)) | ||
} | ||
} | ||
function arrayToDodo(Index) { | ||
export function arrayToDodo(index) { | ||
return function(array, key, map) { | ||
map.set(key, new Dodo(array, Index)) | ||
map.set(key, new Dodo(array, index)) | ||
} | ||
@@ -260,0 +217,0 @@ } |
@@ -86,16 +86,38 @@ import zipObject from 'lodash/zipObject' | ||
export function createGrouper(map, fn, col) { | ||
export function createGrouper(fn, col) { | ||
if (fn) { | ||
return function(row) { | ||
const key = fn(row[col]) | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
if (col == undefined) { | ||
return function(map, row) { | ||
const key = fn(row) | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
return map | ||
} | ||
} else { | ||
return function(map, row) { | ||
const key = fn(row[col]) | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
return map | ||
} | ||
} | ||
} else { | ||
return function(row) { | ||
const key = row[col] | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
if (col == undefined) { | ||
return function(map, row) { | ||
const key = row | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
return map | ||
} | ||
} else { | ||
return function(map, row) { | ||
const key = row[col] | ||
map.has(key) | ||
? map.get(key).push(row) | ||
: map.set(key, [row]) | ||
return map | ||
} | ||
} | ||
@@ -106,2 +128,13 @@ } | ||
export const isfunc = fn => fn && typeof fn == 'function' | ||
export const arrayToIndex = arr => zipObject(arr, [...arr.keys()]) | ||
export const needSlowCase = a => | ||
a.toString().includes('new Take') || a.toString().includes('new Drop') | ||
export function dispatchReduce(fn, initFactory, final) { | ||
if (this.index) | ||
return this.reduceEach(fn, initFactory, final) | ||
else | ||
return this.reduce(fn, initFactory(), final) | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
167967
3294
+ Addedlodash@4.11.2(transitive)
- Removedlodash@4.8.2(transitive)
Updatedlodash@~4.11.0