ui
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Clone helper
|
||||
*
|
||||
* Clone an array or object
|
||||
*
|
||||
* @param items
|
||||
* @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); } }
|
||||
|
||||
module.exports = function clone(items) {
|
||||
var cloned = void 0;
|
||||
|
||||
if (Array.isArray(items)) {
|
||||
var _cloned;
|
||||
|
||||
cloned = [];
|
||||
|
||||
(_cloned = cloned).push.apply(_cloned, _toConsumableArray(items));
|
||||
} else {
|
||||
cloned = {};
|
||||
|
||||
Object.keys(items).forEach(function (prop) {
|
||||
cloned[prop] = items[prop];
|
||||
});
|
||||
}
|
||||
|
||||
return cloned;
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var variadic = require('./variadic');
|
||||
|
||||
/**
|
||||
* Delete keys helper
|
||||
*
|
||||
* Delete one or multiple keys from an object
|
||||
*
|
||||
* @param obj
|
||||
* @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++) {
|
||||
keys[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
variadic(keys).forEach(function (key) {
|
||||
// eslint-disable-next-line
|
||||
delete obj[key];
|
||||
});
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
'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; };
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isArray: function isArray(item) {
|
||||
return Array.isArray(item);
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isObject: function isObject(item) {
|
||||
return (typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object' && Array.isArray(item) === false && item !== null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isFunction: function isFunction(item) {
|
||||
return typeof item === 'function';
|
||||
}
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Get value of a nested property
|
||||
*
|
||||
* @param mainObject
|
||||
* @param key
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
module.exports = function nestedValue(mainObject, key) {
|
||||
try {
|
||||
return key.split('.').reduce(function (obj, property) {
|
||||
return obj[property];
|
||||
}, mainObject);
|
||||
} catch (err) {
|
||||
// If we end up here, we're not working with an object, and @var mainObject is the value itself
|
||||
return mainObject;
|
||||
}
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Values helper
|
||||
*
|
||||
* Retrieve values from [this.items] when it is an array, object or Collection
|
||||
*
|
||||
* @param items
|
||||
* @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); } }
|
||||
|
||||
module.exports = function values(items) {
|
||||
var valuesArray = [];
|
||||
|
||||
if (Array.isArray(items)) {
|
||||
valuesArray.push.apply(valuesArray, _toConsumableArray(items));
|
||||
} else if (items.constructor.name === 'Collection') {
|
||||
valuesArray.push.apply(valuesArray, _toConsumableArray(items.all()));
|
||||
} else {
|
||||
Object.keys(items).forEach(function (prop) {
|
||||
return valuesArray.push(items[prop]);
|
||||
});
|
||||
}
|
||||
|
||||
return valuesArray;
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Variadic helper function
|
||||
*
|
||||
* @param args
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
module.exports = function variadic(args) {
|
||||
if (Array.isArray(args[0])) {
|
||||
return args[0];
|
||||
}
|
||||
|
||||
return args;
|
||||
};
|
||||
Reference in New Issue
Block a user