2020-08-27 05:37:44 +00:00
|
|
|
const async = require("async");
|
2020-10-26 05:07:36 +00:00
|
|
|
const mergeDeep = function(...objects) {
|
|
|
|
const isObject = obj => obj && typeof obj === 'object';
|
|
|
|
|
|
|
|
return objects.reduce((prev, obj) => {
|
|
|
|
Object.keys(obj).forEach(key => {
|
|
|
|
const pVal = prev[key];
|
|
|
|
const oVal = obj[key];
|
|
|
|
|
|
|
|
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
|
|
|
prev[key] = pVal.concat(...oVal);
|
|
|
|
}
|
|
|
|
else if (isObject(pVal) && isObject(oVal)) {
|
|
|
|
prev[key] = mergeDeep(pVal, oVal);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prev[key] = oVal;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
}
|
2020-11-02 05:27:23 +00:00
|
|
|
module.exports = {
|
|
|
|
mergeDeep: mergeDeep,
|
|
|
|
validateIntValue: (value) => {
|
|
|
|
const newValue = !isNaN(parseInt(value)) ? parseInt(value) : null
|
|
|
|
return newValue
|
|
|
|
},
|
|
|
|
arrayContains: (query,theArray) => {
|
|
|
|
var foundQuery = false
|
|
|
|
theArray.forEach((value) => {
|
|
|
|
if(value.indexOf(query) > -1)foundQuery = true
|
|
|
|
})
|
|
|
|
return foundQuery
|
|
|
|
},
|
|
|
|
createQueue: (timeoutInSeconds, queueItemsRunningInParallel) => {
|
|
|
|
return async.queue(function(action, callback) {
|
|
|
|
setTimeout(function(){
|
|
|
|
action(callback)
|
|
|
|
},timeoutInSeconds * 1000 || 1000)
|
|
|
|
},queueItemsRunningInParallel || 3)
|
|
|
|
},
|
|
|
|
copyObject: (obj) => {
|
|
|
|
return Object.assign({},obj)
|
|
|
|
}
|
2020-11-02 01:45:25 +00:00
|
|
|
}
|