From a606a7c010b77b9dc57742bd26b87590f4647711 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 29 Nov 2023 23:09:34 -0800 Subject: [PATCH] fix: add toJSON to BigInt prototype --- src/bundles/explore.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/bundles/explore.js b/src/bundles/explore.js index 11762a7e..9c97c096 100644 --- a/src/bundles/explore.js +++ b/src/bundles/explore.js @@ -21,24 +21,14 @@ const getCidFromCidOrFqdn = (cidOrFqdn) => { } /** - * Get rid of redux-bundler action creator errors for 'Do not know how to serialize a BigInt' when - * they are converted to JSON. + * fix BigInt serialization until https://tc39.es/proposal-bigint/#sec-serializejsonproperty is implemented * - * @template T - * @param {T & Record} node - * @returns {T} + * @see https://github.com/GoogleChromeLabs/jsbi/issues/30 + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json */ -function convertBigIntSizesToNumber (node) { - if (node.size != null) { - node.size = Number(node.size) - } - if (node.links != null) { - node.links = node.links.map(convertBigIntSizesToNumber) - } - if (node.blockSizes != null) { - node.blockSizes = node.blockSizes.map(Number) - } - return node +// eslint-disable-next-line no-extend-native +BigInt.prototype.toJSON = function () { + return this.toString() } // Find all the nodes and path boundaries traversed along a given path @@ -65,10 +55,10 @@ const makeBundle = () => { return { path, - targetNode: convertBigIntSizesToNumber(targetNode), + targetNode, canonicalPath, localPath, - nodes: nodes.map(convertBigIntSizesToNumber), + nodes, pathBoundaries } } catch (error) {