qq-official-bot
Version:
43 lines (42 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepClone = exports.remove = exports.isEmpty = exports.toObject = void 0;
const toObject = (data) => {
if (Buffer.isBuffer(data))
return JSON.parse(data.toString());
if (typeof data === 'object')
return data;
if (typeof data === 'string')
return JSON.parse(data);
throw new Error('Unsupported data type for toObject conversion');
};
exports.toObject = toObject;
const isEmpty = (data) => {
if (!data)
return true;
if (typeof data !== "object")
return false;
return Reflect.ownKeys(data).length === 0;
};
exports.isEmpty = isEmpty;
const remove = (list, item) => {
const index = list.indexOf(item);
if (index !== -1)
list.splice(index, 1);
};
exports.remove = remove;
const deepClone = (obj) => {
if (typeof obj !== "object" || obj === null)
return obj;
if (Array.isArray(obj))
return obj.map(exports.deepClone);
const Constructor = obj.constructor;
const newObj = new Constructor();
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
newObj[key] = (0, exports.deepClone)(obj[key]);
}
}
return newObj;
};
exports.deepClone = deepClone;