From b98a1048f1e239dc888081b9d3a60c661e155a91 Mon Sep 17 00:00:00 2001 From: Nirmal Patel Date: Thu, 8 Feb 2024 20:17:52 +0530 Subject: [PATCH] fix: Function to handle BigInt value in JSON.stringify --- src/condition.js | 5 +++-- src/utils.js | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/utils.js diff --git a/src/condition.js b/src/condition.js index 5f5775dc..9dbf2adb 100644 --- a/src/condition.js +++ b/src/condition.js @@ -1,6 +1,7 @@ 'use strict' import debug from './debug' +import { jsonStringifyWithBigInt } from './utils' export default class Condition { constructor (properties) { @@ -101,9 +102,9 @@ export default class Condition { ]).then(([rightHandSideValue, leftHandSideValue]) => { const result = op.evaluate(leftHandSideValue, rightHandSideValue) debug( - `condition::evaluate <${JSON.stringify(leftHandSideValue)} ${ + `condition::evaluate <${jsonStringifyWithBigInt(leftHandSideValue)} ${ this.operator - } ${JSON.stringify(rightHandSideValue)}?> (${result})` + } ${jsonStringifyWithBigInt(rightHandSideValue)}?> (${result})` ) return { result, diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 00000000..e55197dd --- /dev/null +++ b/src/utils.js @@ -0,0 +1,7 @@ +export function jsonStringifyWithBigInt (data) { + return JSON.stringify(data, + (key, value) => { + return typeof value === "bigint" ? value.toString() : value; + } + ) +}