This commit is contained in:
2022-04-07 18:09:31 +05:30
parent 36ea86d8e6
commit 1c779ef816
14095 changed files with 1769361 additions and 47 deletions
+27
View File
@@ -0,0 +1,27 @@
'use strict';
/**
* Clone helper
*
* Clone an array or object
*
* @param items
* @returns {*}
*/
module.exports = function clone(items) {
let cloned;
if (Array.isArray(items)) {
cloned = [];
cloned.push(...items);
} else {
cloned = {};
Object.keys(items).forEach((prop) => {
cloned[prop] = items[prop];
});
}
return cloned;
};
+19
View File
@@ -0,0 +1,19 @@
'use strict';
const 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, ...keys) {
variadic(keys).forEach((key) => {
// eslint-disable-next-line
delete obj[key];
});
};
+18
View File
@@ -0,0 +1,18 @@
'use strict';
module.exports = {
/**
* @returns {boolean}
*/
isArray: item => Array.isArray(item),
/**
* @returns {boolean}
*/
isObject: item => typeof item === 'object' && Array.isArray(item) === false && item !== null,
/**
* @returns {boolean}
*/
isFunction: item => typeof item === 'function',
};
+17
View File
@@ -0,0 +1,17 @@
'use strict';
/**
* Get value of a nested property
*
* @param mainObject
* @param key
* @returns {*}
*/
module.exports = function nestedValue(mainObject, key) {
try {
return key.split('.').reduce((obj, property) => 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;
}
};
+23
View File
@@ -0,0 +1,23 @@
'use strict';
/**
* Values helper
*
* Retrieve values from [this.items] when it is an array, object or Collection
*
* @param items
* @returns {*}
*/
module.exports = function values(items) {
const valuesArray = [];
if (Array.isArray(items)) {
valuesArray.push(...items);
} else if (items.constructor.name === 'Collection') {
valuesArray.push(...items.all());
} else {
Object.keys(items).forEach(prop => valuesArray.push(items[prop]));
}
return valuesArray;
};
+15
View File
@@ -0,0 +1,15 @@
'use strict';
/**
* Variadic helper function
*
* @param args
* @returns {Array}
*/
module.exports = function variadic(args) {
if (Array.isArray(args[0])) {
return args[0];
}
return args;
};