@onesy/utils
Version:
38 lines (37 loc) • 1.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
// Fix for undefined
// + ref circular values
const method = () => {
const values = new WeakSet();
return (property, value) => {
// Ref circular values
const getValue = (property_, value_) => {
if (typeof value_ === 'object' && value_ !== null) {
if (values.has(value_))
return;
values.add(value_);
}
return value_;
};
if (getValue(property, value) === undefined ||
value === undefined)
return undefined;
return value;
};
};
const stringify = (value_, spaces = 2, replacer = method()) => {
try {
let value = JSON.stringify(value_, replacer, spaces);
// Array circular ref value update
// value = value
// // first item
// .replace(/(?!\[)\n* *null,/g, '')
// // index 1+
// .replace(/,\n* *null/g, '');
return value;
}
catch (error) { }
return String(value_);
};
exports.default = stringify;
;