41 lines
946 B
JavaScript
41 lines
946 B
JavaScript
"use strict";
|
|
function isArray(value) {
|
|
if (typeof Array.isArray === "function") {
|
|
return Array.isArray(value);
|
|
} else {
|
|
return Object.prototype.toString.call(value) === "[object Array]";
|
|
}
|
|
}
|
|
function isObject(value) {
|
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
}
|
|
function isEmpty(value) {
|
|
if (value === "" || value === void 0 || value === null) {
|
|
return true;
|
|
}
|
|
if (isArray(value)) {
|
|
return value.length === 0;
|
|
}
|
|
if (isObject(value)) {
|
|
return Object.keys(value).length === 0;
|
|
}
|
|
return false;
|
|
}
|
|
function cloneDeep(obj) {
|
|
const d = isArray(obj) ? [...obj] : {};
|
|
if (isObject(obj)) {
|
|
for (const key in obj) {
|
|
if (obj[key]) {
|
|
if (obj[key] && typeof obj[key] === "object") {
|
|
d[key] = cloneDeep(obj[key]);
|
|
} else {
|
|
d[key] = obj[key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return d;
|
|
}
|
|
exports.cloneDeep = cloneDeep;
|
|
exports.isEmpty = isEmpty;
|