@camunda8/sdk
Version:
[](https://www.npmjs.com/package/@camunda8/sdk)
48 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = void 0;
class Utils {
/**
* Throw an Error if the variable passed is not a number
*/
static validateNumber(variable, field) {
const value = Number(variable);
if (!Number.isInteger(value)) {
throw new Error(`
${field} is malformed, value : ${variable}
`);
}
}
static deepClone(obj, hash = new WeakMap()) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (hash.has(obj)) {
return hash.get(obj);
}
let result;
if (obj instanceof Date) {
result = new Date(obj);
}
else if (obj instanceof RegExp) {
result = new RegExp(obj.source, obj.flags);
}
else if (obj instanceof Array) {
result = [];
hash.set(obj, result);
obj.forEach((item, index) => {
result[index] = Utils.deepClone(item, hash);
});
}
else {
result = {};
hash.set(obj, result);
Object.keys(obj).forEach((key) => {
result[key] = Utils.deepClone(obj[key], hash);
});
}
return result;
}
}
exports.Utils = Utils;
//# sourceMappingURL=utils.js.map