mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-04 07:46:21 +02:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
"use strict";
|
|
/*
|
|
* @poppinss/utils
|
|
*
|
|
* (c) Harminder Virk <virk@adonisjs.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.safeStringify = void 0;
|
|
const fast_safe_stringify_1 = require("./fast-safe-stringify");
|
|
/**
|
|
* Replacer to handle bigints and remove Circular values all together
|
|
*/
|
|
function jsonStringifyReplacer(replacer, removeCircular) {
|
|
return function (key, value) {
|
|
if (removeCircular && value === '[Circular]') {
|
|
return;
|
|
}
|
|
const val = replacer ? replacer.call(this, key, value) : value;
|
|
if (typeof val === 'bigint') {
|
|
return val.toString();
|
|
}
|
|
return val;
|
|
};
|
|
}
|
|
/**
|
|
* Safely stringifies a Javascript native value
|
|
*/
|
|
function safeStringify(value, replacer, space) {
|
|
try {
|
|
return JSON.stringify(value, jsonStringifyReplacer(replacer, false), space);
|
|
}
|
|
catch {
|
|
return (0, fast_safe_stringify_1.stringify)(value, jsonStringifyReplacer(replacer, true), space);
|
|
}
|
|
}
|
|
exports.safeStringify = safeStringify;
|