Skip to content

Commit

Permalink
Merge branch 'release/4.34.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrmnn committed Jun 2, 2022
2 parents 9964bc6 + 0734322 commit 4b240b4
Show file tree
Hide file tree
Showing 101 changed files with 596 additions and 311 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ All available methods
- [toArray](#toarray)
- [toJson](#tojson)
- [transform](#transform)
- [undot](#undot)
- [union](#union)
- [unique](#unique)
- [unless](#unless)
Expand Down Expand Up @@ -2768,6 +2769,41 @@ collection.all();

> Unlike most other collection methods, `transform` modifies the collection itself. If you wish to create a new collection instead, use the `map` method.
#### `undot()`

The `undot` method expands a single-dimensional collection that uses "dot" notation into a multi-dimensional collection:

```js
const person = collect({
'name.first_name': 'Marie',
'name.last_name': 'Valentine',
'address.line_1': '2992 Eagle Drive',
'address.line_2': '',
'address.suburb': 'Detroit',
'address.state': 'MI',
'address.postcode': '48219',
});

const undotted = person.undot();

const all = undotted.all();

// {
// name: {
// first_name: 'Marie',
// last_name: 'Valentine',
// },
// address: {
// line_1: '2992 Eagle Drive',
// line_2: '',
// suburb: 'Detroit',
// state: 'MI',
// postcode: '48219',
// },
// }
```


#### `union()`

The union method adds the given array to the collection. If the given array contains keys that are already in the original collection, the original collection's values will be preferred:
Expand Down
190 changes: 101 additions & 89 deletions build/collect.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/collect.min.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions dist/helpers/clone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/**
* Clone helper
*
Expand All @@ -9,10 +8,20 @@
* @returns {*}
*/

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

module.exports = function clone(items) {
var cloned = void 0;
var cloned;

if (Array.isArray(items)) {
var _cloned;
Expand All @@ -22,7 +31,6 @@ module.exports = function clone(items) {
(_cloned = cloned).push.apply(_cloned, _toConsumableArray(items));
} else {
cloned = {};

Object.keys(items).forEach(function (prop) {
cloned[prop] = items[prop];
});
Expand Down
5 changes: 3 additions & 2 deletions dist/helpers/deleteKeys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var variadic = require('./variadic');

/**
* Delete keys helper
*
Expand All @@ -11,8 +10,10 @@ var variadic = require('./variadic');
* @param keys
* @returns {void}
*/


module.exports = function deleteKeys(obj) {
for (var _len = arguments.length, keys = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
keys[_key - 1] = arguments[_key];
}

Expand Down
4 changes: 2 additions & 2 deletions dist/helpers/is.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

module.exports = {
/**
Expand All @@ -14,7 +14,7 @@ module.exports = {
* @returns {boolean}
*/
isObject: function isObject(item) {
return (typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object' && Array.isArray(item) === false && item !== null;
return _typeof(item) === 'object' && Array.isArray(item) === false && item !== null;
},

/**
Expand Down
1 change: 0 additions & 1 deletion dist/helpers/nestedValue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/**
* Get value of a nested property
*
Expand Down
13 changes: 11 additions & 2 deletions dist/helpers/values.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/**
* Values helper
*
Expand All @@ -9,7 +8,17 @@
* @returns {*}
*/

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

module.exports = function values(items) {
var valuesArray = [];
Expand Down
1 change: 0 additions & 1 deletion dist/helpers/variadic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

/**
* Variadic helper function
*
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

function Collection(collection) {
if (collection !== undefined && !Array.isArray(collection) && (typeof collection === 'undefined' ? 'undefined' : _typeof(collection)) !== 'object') {
if (collection !== undefined && !Array.isArray(collection) && _typeof(collection) !== 'object') {
this.items = [collection];
} else if (collection instanceof this.constructor) {
this.items = collection.all();
} else {
this.items = collection || [];
}
}

/**
* Symbol.iterator
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator
*/


var SymbolIterator = require('./methods/symbol.iterator');

if (typeof Symbol !== 'undefined') {
Collection.prototype[Symbol.iterator] = SymbolIterator;
}

/**
* Support JSON.stringify
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
*/


Collection.prototype.toJSON = function toJSON() {
return this.items;
};
Expand Down Expand Up @@ -131,6 +133,7 @@ Collection.prototype.times = require('./methods/times');
Collection.prototype.toArray = require('./methods/toArray');
Collection.prototype.toJson = require('./methods/toJson');
Collection.prototype.transform = require('./methods/transform');
Collection.prototype.undot = require('./methods/undot');
Collection.prototype.unless = require('./methods/unless');
Collection.prototype.unlessEmpty = require('./methods/whenNotEmpty');
Collection.prototype.unlessNotEmpty = require('./methods/whenEmpty');
Expand Down Expand Up @@ -158,5 +161,5 @@ var collect = function collect(collection) {

module.exports = collect;
module.exports.collect = collect;
module.exports.default = collect;
module.exports["default"] = collect;
module.exports.Collection = Collection;
5 changes: 1 addition & 4 deletions dist/methods/chunk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

module.exports = function chunk(size) {
var _this = this;
Expand All @@ -12,7 +12,6 @@ module.exports = function chunk(size) {
do {
var items = this.items.slice(index, index + size);
var collection = new this.constructor(items);

chunks.push(collection);
index += size;
} while (index < this.items.length);
Expand All @@ -22,11 +21,9 @@ module.exports = function chunk(size) {
var _loop = function _loop() {
var keysOfChunk = keys.slice(index, index + size);
var collection = new _this.constructor({});

keysOfChunk.forEach(function (key) {
return collection.put(key, _this.items[key]);
});

chunks.push(collection);
index += size;
};
Expand Down
12 changes: 11 additions & 1 deletion dist/methods/collapse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

module.exports = function collapse() {
var _ref;
Expand Down
16 changes: 13 additions & 3 deletions dist/methods/combine.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
'use strict';

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"); } }; }();
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

module.exports = function combine(array) {
var _this = this;
Expand All @@ -19,7 +29,7 @@ module.exports = function combine(array) {
this.items.forEach(function (key, iterator) {
collection[key] = values[iterator];
});
} else if (_typeof(this.items) === 'object' && (typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object') {
} else if (_typeof(this.items) === 'object' && _typeof(values) === 'object') {
Object.keys(this.items).forEach(function (key, index) {
collection[_this.items[key]] = values[Object.keys(values)[index]];
});
Expand Down
8 changes: 3 additions & 5 deletions dist/methods/concat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

var clone = require('../helpers/clone');

Expand All @@ -9,24 +9,22 @@ module.exports = function concat(collectionOrArrayOrObject) {

if (collectionOrArrayOrObject instanceof this.constructor) {
list = collectionOrArrayOrObject.all();
} else if ((typeof collectionOrArrayOrObject === 'undefined' ? 'undefined' : _typeof(collectionOrArrayOrObject)) === 'object') {
} else if (_typeof(collectionOrArrayOrObject) === 'object') {
list = [];
Object.keys(collectionOrArrayOrObject).forEach(function (property) {
list.push(collectionOrArrayOrObject[property]);
});
}

var collection = clone(this.items);

list.forEach(function (item) {
if ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object') {
if (_typeof(item) === 'object') {
Object.keys(item).forEach(function (key) {
return collection.push(item[key]);
});
} else {
collection.push(item);
}
});

return new this.constructor(collection);
};
13 changes: 11 additions & 2 deletions dist/methods/contains.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var values = require('../helpers/values');

Expand Down Expand Up @@ -30,6 +40,5 @@ module.exports = function contains(key, value) {

var keysAndValues = values(this.items);
keysAndValues.push.apply(keysAndValues, _toConsumableArray(Object.keys(this.items)));

return keysAndValues.indexOf(key) !== -1;
};
1 change: 0 additions & 1 deletion dist/methods/countBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = function countBy() {
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (value) {
return value;
};

return new this.constructor(this.items).groupBy(fn).map(function (value) {
return value.count();
});
Expand Down
2 changes: 1 addition & 1 deletion dist/methods/crossJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function crossJoin() {
return result;
}

for (var _len = arguments.length, values = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
values[_key] = arguments[_key];
}

Expand Down
3 changes: 1 addition & 2 deletions dist/methods/diff.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = function diff(values) {
var valuesToDiff = void 0;
var valuesToDiff;

if (values instanceof this.constructor) {
valuesToDiff = values.all();
Expand All @@ -12,6 +12,5 @@ module.exports = function diff(values) {
var collection = this.items.filter(function (item) {
return valuesToDiff.indexOf(item) === -1;
});

return new this.constructor(collection);
};

0 comments on commit 4b240b4

Please sign in to comment.