dtrim
Version:
A tool for trimming deep/lenghty javascript structures. Some potential usages are: debugging, logging or data sanitization.
28 lines • 825 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSize = exports.getTag = void 0;
const toString = Object.prototype.toString;
const mapTag = '[object Map]';
const setTag = '[object Set]';
const getTag = (value) => {
if (value == null) {
return value === undefined ? '[object Undefined]' : '[object Null]';
}
return toString.call(value);
};
exports.getTag = getTag;
const getSize = (collection) => {
if (collection == null) {
return 0;
}
if (Array.isArray(collection)) {
return collection.length;
}
const tag = (0, exports.getTag)(collection);
if (tag === mapTag || tag === setTag) {
return collection.size;
}
return Object.keys(collection).length;
};
exports.getSize = getSize;
//# sourceMappingURL=utils.js.map