{"name":"lossless-json","version":"4.3.2","keywords":["json","lossless","parse","stringify","long","bigint","bignumber","number","date","safe"],"author":{"name":"Jos de Jong"},"license":"MIT","_id":"lossless-json@4.3.2","maintainers":[{"name":"josdejong","email":"email@josdejong.com"}],"homepage":"https://github.com/josdejong/lossless-json#readme","bugs":{"url":"https://github.com/josdejong/lossless-json/issues"},"dist":{"shasum":"598f8aafdc569963cb3c3daae0e89ca9464ce632","tarball":"http://registry-npm.ywwl.com/lossless-json/download/lossless-json-4.3.2.tgz","fileCount":68,"integrity":"sha512-TWT1oIGJKaHkme0nDFoW9Tsv0/IZxy6P8rzD03hZpk7de04PWGfl/uMj/WcENrJLNF4P+QGGByPjap6qx++bDQ==","signatures":[{"sig":"MEUCIQDitb89ztp7/7YTnOtoq9GOnQcDxHngbppa4RT0TtIwAAIgSQczFvITsfESdNnBL44VJV7UaOhfqhZldcSAwoZcYHw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIE5n9YqKG1mgoyRiesICB+d2Lrherf/RoMqZWBQumBUzAiAmguSzK00B0HyVQ6iu000ZE4MWpO3rfXr87UYmT9rzKQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":362862,"size":83763,"noattachment":false,"key":"/lossless-json/-/lossless-json-4.3.2.tgz"},"main":"lib/umd/lossless-json.js","types":"lib/types/index.d.ts","module":"lib/esm/index.js","browser":"lib/umd/lossless-json.js","exports":{".":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.js","require":"./lib/umd/lossless-json.js"}},"gitHead":"150551cdb5d135f3e4f481bf0b6d338e0f296a41","scripts":{"lint":"biome check","test":"vitest watch src","build":"npm-run-all build:**","format":"biome check --write","prepare":"husky","release":"npm-run-all release:**","test-ci":"vitest run src","benchmark":"npm run build:esm && node tools/benchmark/run.mjs","build:esm":"babel src --out-dir lib/esm --extensions \".ts\" --source-maps --config-file ./babel.config.json","build:umd":"rollup --config rollup.config.mjs","build:clean":"del-cli lib","build:types":"tsc --project tsconfig-types.json","release:push":"git push && git push --tag","build:esm:cpy":"cpy tools/esm/package.json lib/esm --flat","build:umd:cpy":"cpy tools/cjs/package.json lib/umd --flat","build-and-test":"npm run test-ci && npm run lint && npm run build","build:validate":"vitest run test-lib","release-dry-run":"npm run build-and-test && standard-version --dry-run","release:publish":"npm publish","release:version":"standard-version","release:build-and-test":"npm run build-and-test"},"_npmUser":{"name":"josdejong","email":"email@josdejong.com"},"repository":{"url":"git+https://github.com/josdejong/lossless-json.git","type":"git"},"_npmVersion":"11.13.0","description":"Parse JSON without risk of losing numeric information","directories":{},"sideEffects":false,"_nodeVersion":"24.16.0","_hasShrinkwrap":false,"devDependencies":{"husky":"9.1.7","rollup":"4.64.7","vitest":"5.0.5","cpy-cli":"7.0.0","del-cli":"8.0.1","globals":"17.13.0","tinybench":"6.2.2","@babel/cli":"8.0.6","decimal.js":"10.6.0","typescript":"7.0.2","@babel/core":"8.0.7","@types/node":"26.6.5","npm-run-all":"4.1.5","@biomejs/biome":"2.5.15","@commitlint/cli":"21.2.3","@types/benchmark":"2.1.5","standard-version":"9.5.0","@babel/preset-env":"8.0.7","@rollup/plugin-terser":"1.0.0","@babel/preset-typescript":"8.0.7","@commitlint/config-conventional":"21.2.3","@babel/plugin-transform-typescript":"8.0.6"},"_npmOperationalInternal":{"tmp":"tmp/lossless-json_4.3.2_1792144569339_0.3794002680343507","host":"s3://npm-registry-packages-npm-production"},"readme":"# lossless-json\n\nParse JSON without risk of losing numeric information.\n\n```js\nimport { parse, stringify } from 'lossless-json'\n\nconst text = '{\"decimal\":2.370,\"long\":9123372036854000123,\"big\":2.3e+500}'\n\n// JSON.parse will lose some digits and a whole number:\nconsole.log(JSON.stringify(JSON.parse(text)))\n// '{\"decimal\":2.37,\"long\":9123372036854000000,\"big\":null}'\n// WHOOPS!!!\n\n// LosslessJSON.parse will preserve all numbers and even the formatting:\nconsole.log(stringify(parse(text)))\n// '{\"decimal\":2.370,\"long\":9123372036854000123,\"big\":2.3e+500}'\n```\n\nThe following in-depth article explains what happens there: [Why does JSON.parse corrupt large numbers and how to solve this?](https://jsoneditoronline.org/indepth/parse/why-does-json-parse-corrupt-large-numbers/)\n\n**How does it work?** The library works exactly the same as the native `JSON.parse` and `JSON.stringify`. The difference is that `lossless-json` preserves information of big numbers. `lossless-json` parses numeric values not as a regular number but as a `LosslessNumber`, a lightweight class which stores the numeric value as a string. One can perform regular operations with a `LosslessNumber`, and it will throw an error when this would result in losing information.\n\n**When to use?** If you have to deal with JSON data that contains `long` values for example, coming from an application like C++, Java, or C#. The trade-off is that `lossless-json` is slower than the native `JSON.parse` and `JSON.stringify` functions, so be careful when performance is a bottleneck for you.\n\nFeatures:\n\n- No risk of losing numeric information when working with big numbers.\n- Maintain the formatting of numbers.\n- Parse error on duplicate keys.\n- Built-in support for `bigint`.\n- Built-in support for `Date` (turned off by default).\n- Customizable: parse numeric values into any data type, like `BigNumber`, `bigint`, `number`, or a mix of them.\n- Compatible with the native, built-in `JSON.parse` and `JSON.stringify`.\n- Helpful error messages when parsing invalid JSON.\n- Works in browsers and node.js.\n- Comes with TypeScript typings included.\n- Modular: ES module functions, only load and bundle what you use.\n- Small: the full bundle is less than `4 kB` in size when minified and gzipped.\n\n## Install\n\nInstall via [npm](https://www.npmjs.com/package/lossless-json):\n\n```\nnpm install lossless-json\n```\n\n## Use\n\n### Parse and stringify\n\nParsing and stringification works as you're used to:\n\n```js\nimport { parse, stringify } from 'lossless-json'\n\nconst json = parse('{\"foo\":\"bar\"}') // {foo: 'bar'}\nconst text = stringify(json) // '{\"foo\":\"bar\"}'\n```\n\n### LosslessNumbers\n\nNumbers are parsed into a `LosslessNumber`, which can be used like a regular number in numeric operations. Converting to a number will throw an error when this would result in losing information due to truncation, overflow, or underflow.\n\n```js\nimport { isLosslessNumber, parse } from 'lossless-json'\n\nconst text = '{\"normal\":2.3,\"long\":123456789012345678901,\"big\":2.3e+500}'\nconst json = parse(text)\n\nconsole.log(isLosslessNumber(json.normal)) // true\nconsole.log(json.normal.valueOf()) // number, 2.3\n\n// LosslessNumbers can be used as regular numbers\nconsole.log(json.normal + 2) // number, 4.3\n\n// but the following operation will throw an error as it would result in information loss\nconsole.log(json.long + 1)\n// throws Error: Cannot safely convert LosslessNumber to number:\n//   \"123456789012345678901\" will be parsed as 123456789012345680000 and lose information\n```\n\n### BigInt\n\nJavaScript natively supports `bigint`: big integers that can hold a large number of digits, instead of the about 15 digits that a regular `number` can hold. It is a typical use case to want to parse integer numbers into a `bigint`, and all other values into a regular `number`. This can be achieved with a custom `numberParser`:\n\n```js\nimport { parse, isInteger } from 'lossless-json'\n\nconst options = {\n  // parse integer values into a bigint, and use a regular number otherwise\n  numberParser: (value) => {\n    return isInteger(value) ? BigInt(value) : parseFloat(value)\n  }\n}\n\nconst text = '[123456789123456789123456789, 2.3, 123]'\nconst json = parse(text, null, options)\n// output:\n// [\n//   123456789123456789123456789n, // bigint\n//   2.3, // number\n//   123n // bigint\n// ]\n```\n\nYou can adjust the logic to your liking, using utility functions like `isInteger`, `isNumber`, `isSafeNumber`. The number parser shown above is included in the library and is named `parseNumberAndBigInt`.\n\n\n### BigInt support using native `JSON.parse`\n\nSince some time, the reviver callback of the native `JSON.parse` function has a new parameter `context.source`. This new parameter allows to parse numeric values into any data type like `BigInt` or `BigNumber`, similar to the `numberParser` callback of `lossless-json`. So for parsing `BigInt` or `BigNumber` values, it is no longer necessary to use a special library like `lossless-json`.\n\n> IMPORTANT: since `context.source` is quite a new JavaScript feature, it is important to check browser compatibility, see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON#browser_compatibility) or [caniuse.com](https://caniuse.com/?search=context.source).\n\nStringifying `BigInt` values is not possible, unless you want to serialize them into a string with quotes. That is possible by [monkey patching a method `BigInt.prototype.toJSON`](https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-1006088574). However, when parsing this data again, it is not possible to know whether a string containing an integer number was intended to be a string or a bigint.\n\nHere is a minimal example of parsing data with support for `BigInt` using the native `JSON.parse`. A similar solution can be worked out for other data types.\n\n```js\nfunction parseWithBigInt(text) {\n  const intRegex = /^-?\\d+$/\n\n  return JSON.parse(text, (_key, value, context) => {\n    const isBigInt = \n      typeof value === 'number' &&\n      (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) && \n      intRegex.test(context.source)\n    \n    return isBigInt\n        ? BigInt(context.source) \n        : value\n    })\n}\n\nconst text = '{\"number\":1.23,\"int\":42,\"bigint\":9123372036854000123}'\nconst data = parseWithBigInt(text)\nconsole.log(data)\n// {\n//   number: 1.23,\n//   int: 42,\n//   bigint: 9123372036854000123n\n// }\n```\n\n### Validate safe numbers\n\nIf you want parse a json string into an object with regular numbers, but want to validate that no numeric information is lost, you write your own number parser and use `isSafeNumber` to validate the numbers:\n\n```js\nimport { parse, isSafeNumber } from 'lossless-json'\n\nconst options = {\n  parseNumber: (value) => {\n    if (!isSafeNumber(value)) {\n      throw new Error(`Cannot safely convert value '${value}' into a number`)\n    }\n\n    return parseFloat(value)\n  }\n}\n\n// will parse with success if all values can be represented with a number\nlet json = parse('[1,2,3]', undefined, options)\nconsole.log(json) // [1, 2, 3] (regular numbers)\n\n// will throw an error when some of the values are too large to represent correctly as number\ntry {\n  let json = parse('[1,2e+500,3]', undefined, options)\n} catch (err) {\n  console.log(err) // throws Error 'Cannot safely convert value '2e+500' into a number'\n}\n```\n\n### BigNumbers\n\nTo use the library in conjunction with your favorite BigNumber library, for example [decimal.js](https://github.com/MikeMcl/decimal.js/), you have to define a custom number parser and stringifier:\n\n```js\nimport { parse, stringify } from 'lossless-json'\nimport Decimal from 'decimal.js'\n\nconst parseDecimal = (value) => new Decimal(value)\n\nconst decimalStringifier = {\n  test: (value) => Decimal.isDecimal(value),\n  stringify: (value) => value.toString()\n}\n\n// parse JSON, operate on a Decimal value, then stringify again\nconst text = '{\"value\":2.3e500}'\nconst json = parse(text, undefined, { parseNumber: parseDecimal }) \n// {value: new Decimal('2.3e500')}\n\nconst output = {\n  result: json.value.times(2)\n}\n// {result: new Decimal('4.6e500')}\n\nconst str = stringify(output, undefined, undefined, [decimalStringifier])\n// '{\"result\":4.6e500}'\n```\n\n### Reviver and replacer\n\nThe library is compatible with the native `JSON.parse` and `JSON.stringify`, and also comes with the optional `reviver` and `replacer` arguments that allow you to serialize for example data classes in a custom way. Here is an example demonstrating how you can stringify a `Date` in a different way than the built-in `reviveDate` utility function.\n\nThe following example stringifies a `Date` as an object with a `$date` key instead of a string, so it is uniquely recognizable when parsing the structure:\n\n```js\nimport { parse, stringify } from 'lossless-json'\n\n// stringify a Date as a unique object with a key '$date', so it is recognizable\nfunction customDateReplacer(key, value) {\n  if (value instanceof Date) {\n    return {\n      $date: value.toISOString()\n    }\n  }\n\n  return value\n}\n\nfunction isJSONDateObject(value) {\n  return value && typeof value === 'object' && typeof value.$date === 'string'\n}\n\nfunction customDateReviver(key, value) {\n  if (isJSONDateObject(value)) {\n    return new Date(value.$date)\n  }\n\n  return value\n}\n\nconst record = {\n  message: 'Hello World',\n  timestamp: new Date('2022-08-30T09:00:00Z')\n}\n\nconst text = stringify(record, customDateReplacer)\nconsole.log(text)\n// output:\n//   '{\"message\":\"Hello World\",\"timestamp\":{\"$date\":\"2022-08-30T09:00:00.000Z\"}}'\n\nconst parsed = parse(text, customDateReviver)\nconsole.log(parsed)\n// output:\n//   {\n//     action: 'create',\n//     timestamp: new Date('2022-08-30T09:00:00.000Z')\n//   }\n```\n\n## API\n\n### parse(text [, reviver [, options]])\n\nThe `LosslessJSON.parse()` function parses a string as JSON, optionally transforming the value produced by parsing.\n\n- **@param** `{string} text`\n  The string to parse as JSON. See the JSON object for a description of JSON syntax.\n- **@param** `{(key: string, value: unknown) => unknown} [reviver]`\n  If a function, prescribes how the value originally produced by parsing is transformed, before being returned.\n- **@param** `ParseOptions | ParseNumber [options]` Pass options to customize the way numbers are parsed and duplicate keys are handled. See description below. For backward compatibility it is possible to pass a `parseNumber` function here instead of an object with property `parseNumber`. \n- **@returns** `{unknown}`\n  Returns the Object corresponding to the given JSON text.\n- **@throws** Throws a SyntaxError exception if the string to parse is not valid JSON.\n\n#### options\n\nThe `options` argument in the function `parse` is either an object with properties `{ parseNumber, onDuplicateKey }`, or it is a `parseNumber` function (for backward compatibility). It has the following properties:\n\n- **@param** `{function(value: string) : unknown} [parseNumber]`\n  Pass an optional custom number parser. Input is a string, and the output can be any numeric value: `number`, `bigint`, `LosslessNumber`, or a custom `BigNumber` library. By default, all numeric values are parsed into a `LosslessNumber`.\n- **@param** `{function(info: { key: string, position: number, oldValue: unknown, newValue: unknown }) : unknown | undefined} [onDuplicateKey]`\n  Customize the behavior in case of duplicate keys. By default, and error is thrown in case of duplicate keys. To alter this behavior, a custom `onDuplicateKey` callback can be provided. There are a few typical cases:\n  - Return the `oldValue` (first value) in order to keep that in case of duplicates.\n    ```js\n    onDuplicateKey: ({ oldValue }) => oldValue\n    ```\n  - Return the `newValue` (latest value) in order to keep that in case of duplicates:\n    ```js\n    onDuplicateKey: ({ newValue }) => newValue\n    ```\n  - Return `undefined` in order to ignore duplicate keys and keep the `oldValue` (first value):\n    ```js\n    onDuplicateKey: () => {}\n    ```\n  - Throw a custom error message. Can also be used for logging all occurrences:\n    ```js\n    onDuplicateKey: ({ key, position, oldValue, newValue }) => {\n      console.error('Duplicate key error', { key, position, oldValue, newValue })\n      throw new Error(`Duplicate key ${key} at position ${position}`)\n    }\n    ```\n\n### stringify(value [, replacer [, space [, numberStringifiers]]])\n\nThe `LosslessJSON.stringify()` function converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\n\n- **@param** `{unknown} value`\n  The value to convert to a JSON string.\n- **@param** `{((key: string, value: unknown) => unknown) | Array.<string | number>} [replacer]`\n  A function that alters the behavior of the stringification process, or an array with strings or numbers that serve as a whitelist for selecting the properties of the value object to be included in the JSON string. If this value is `null` or not provided, all properties of the object are included in the resulting JSON string.\n- **@param** `{number | string | undefined} [space]`\n  A `string` or `number` that is used to insert white space into the output JSON string for readability purposes. If this is a `number`, it indicates the number of space characters to use as white space. Values less than 1 indicate that no space should be used. If this is a `string`, the `string` is used as white space. If this parameter is not provided (or is `null`), no white space is used.\n- **@param** `{Array<{test: (value: unknown) => boolean, stringify: (value: unknown) => string}>} [numberStringifiers]`\n  An optional list with additional number stringifiers, for example to serialize a `BigNumber`. The output of the function must be valid stringified JSON number. When `undefined` is returned, the property will be deleted from the object. The difference with using a `replacer` is that the output of a `replacer` must be JSON and will be stringified afterwards, whereas the output of the `numberStringifiers` is already stringified JSON.\n- **@returns** `{string | undefined}`\n  Returns the string representation of the JSON object.\n- **@throws** Throws a SyntaxError when one of the `numberStringifiers` does not return valid output.\n\n### LosslessNumber\n\n#### Construction\n\n```\nnew LosslessNumber(value: number | string) : LosslessNumber\n```\n\n#### Methods\n\n- `.valueOf(): number | bigint`\n  Convert the `LosslessNumber` into a regular `number` or `bigint`. A `number` is returned for safe numbers and decimal values that only lose some insignificant digits. A `bigint` is returned for large integer numbers. An `Error` is thrown for values that will overflow or underflow. Examples:\n\n  ```js\n  // a safe number\n  console.log(new LosslessNumber('23.4').valueOf())\n  // number 23.4\n\n  // a decimal losing insignificant digits\n  console.log(new LosslessNumber('0.66666666666666666666667').valueOf())\n  // number 0.6666666666666666\n\n  // a large integer\n  console.log(new LosslessNumber('9123372036854000123').valueOf())\n  // bigint 9123372036854000123\n\n  // a value that will overflow\n  console.log(new LosslessNumber('2.3e+500').valueOf())\n  // Error: Cannot safely convert to number: the value '2.3e+500' would overflow and become Infinity\n\n  // a value that will underflow\n  console.log(new LosslessNumber('2.3e-500').valueOf())\n  // Error: Cannot safely convert to number: the value '2.3e-500' would underflow and become 0\n  ```\n\n  Note that you can implement your own strategy for conversion by just getting the value as string via `.toString()`, and using util functions like `isInteger`, `isSafeNumber`, `getUnsafeNumberReason`, and `toSafeNumberOrThrow` to convert it to a numeric value.\n\n- `.toString() : string`\n  Get the string representation of the lossless number.\n\n#### Properties\n\n- `{boolean} .isLosslessNumber : true`\n  **Deprecated.** Lossless numbers retain this boolean field for existing callers. Use the\n  `isLosslessNumber(value)` function to distinguish them from ordinary objects\n  containing a field with the same name.\n\n### Utility functions\n\n- `isInteger(value: string) : boolean`\n\n  Test whether a string contains an integer value, like `'2300'` or `10`.\n\n- `isNumber(value: string) : boolean`\n\n  Test whether a string contains a numeric value, like `'2.4'` or `'1.4e+3'`.\n\n- `isSafeNumber(value: string, config?: { approx: boolean }): boolean`\n\n  Test whether a string contains a numeric value which can be safely represented by a JavaScript `number` without losing any information. Returns false when digits would be truncated of an integer or decimal, or when the number would overflow or underflow. When passing `{ approx: true }` as config, the function will be less strict and allow losing insignificant digits of a decimal value. Examples:\n\n  ```js\n  isSafeNumber('1.55e3') // true\n  isSafeNumber('2e500') // false\n  isSafeNumber('2e-500') // false\n  isSafeNumber('9123372036854000123') // false\n  isSafeNumber('0.66666666666666666667') // false\n  isSafeNumber('9123372036854000123', { approx: true }) // false\n  isSafeNumber('0.66666666666666666667', { approx: true }) // true\n  ```\n\n- `toSafeNumberOrThrow(value: string, config?: { approx: boolean }) : number`\n\n  Convert a string into a number when it is safe to do so, otherwise throw an informative error.\n\n- `getUnsafeNumberReason(value): UnsafeNumberReason | undefined`\n\n  When the provided `value` is an unsafe number, describe what the reason is: `overflow`, `underflow`, `truncate_integer`, `truncate_float`. Returns `undefined` when the value is safe.\n\n- `isLosslessNumber(value: unknown) : boolean`\n\n  Test whether a value is a `LosslessNumber`.\n\n- `toLosslessNumber(value: number) : LosslessNumber`\n\n  Convert a `number` into a `LosslessNumber`. The function will throw an exception when the `number` is exceeding the maximum safe limit of 15 digits (hence being truncated itself) or is `NaN` or `Infinity`.\n\n- `parseLosslessNumber(value: string) : LosslessNumber`\n\n  The default `numberParser` used by `parse`. Creates a `LosslessNumber` from a string containing a numeric value.\n\n- `parseNumberAndBigInt(value: string) : number | bigint`\n\n  A custom `numberParser` that can be used by `parse`. The parser will convert integer values into `bigint`, and converts al other values into a regular `number`.\n\n- `reviveDate(key, value)`\n\n  Revive strings containing an ISO 8601 date string into a JavaScript `Date` object. This reviver is not turned on by default because there is a small risk of parsing a text field that _accidentally_ contains a date into a `Date`. Whether `reviveDate` is safe to use depends on the use case. Usage:\n\n  ```js\n  import { parse, reviveDate } from 'lossless-json'\n\n  const data = parse('[\"2022-08-25T09:39:19.288Z\"]', reviveDate)\n  // output:\n  // [\n  //   new Date('2022-08-25T09:39:19.288Z')\n  // ]\n  ```\n\n  An alternative solution is to stringify a `Date` in a specific recognizable object like `{'$date':'2022-08-25T09:39:19.288Z'}`, and use a reviver and replacer to turn this object into a `Date` and vice versa.\n\n- `splitNumber(value: string) : { sign: '-' | '', digits: string, exponent: number }`\n\n  Split a number in its sign, digits, and exponent. For example `splitNumber(\"23.50\")` returns `{sign: '', digits: '235', exp: 1 }`. The value can be constructed again from a split number by inserting a dot at the second character of the digits if there is more than one digit, prepending it with the sign, and appending the exponent like `e${exponent}`\n- `compareNumber(a: string, b: string) : -1 | 0 | 1`\n\n  Compare two strings containing a numeric value based on their numerical value. For example, the numeric value of `\"5e3\"` is larger than `\"70\"`, but comparing the string characters concludes otherwise. The function returns `1` when `a` is larger than `b`, `0` when they are equal,  and `-1` when `a` is smaller than `b`. This method works safely for values with a large number of digits.\n- `compareLosslessNumber(a: LosslessNumber, b: LosslessNumber) : -1 | 0 | 1`\n\n  Compare two lossless numbers numerically. The function returns `1` when `a` is larger than `b`, `0` when they are equal,  and `-1` when `a` is smaller than `b`. The compare function can be used to sort an array with `LosslessNumber` for example:\n\n  ```js\n  import { LosslessNumber, compareLosslessNumber } from 'lossless-json'\n  \n  const values = [\n    new LosslessNumber('5e3'),\n    new LosslessNumber('70'),\n    new LosslessNumber('0.02e5')\n  ]\n  \n  const sorted = values.toSorted(compareLosslessNumber)\n  // sorted = [\n  //  new LosslessNumber('70'),\n  //  new LosslessNumber('0.02e5'),\n  //  new LosslessNumber('5e3')\n  //]\n  ```\n\n## Alternatives\n\nSimilar libraries:\n\n- https://github.com/BridgeAR/safe-stable-stringify\n- https://github.com/nicolasparada/js-json-bigint\n- https://github.com/Ivan-Korolenko/json-with-bigint\n- https://github.com/sidorares/json-bigint (not actively maintained)\n- https://github.com/jawj/json-custom-numbers\n- https://github.com/epoberezkin/json-source-map\n- Or: [use native `JSON.parse` with `context.source`](#bigint-support-using-native-jsonparse)\n\n## Test\n\nTo test the library, first install dependencies once:\n\n```\nnpm install\n```\n\nTo run the unit tests:\n\n```\nnpm test\n```\n\nTo build the library and run the unit tests and integration tests:\n\n```\nnpm run build-and-test\n```\n\n## Lint\n\nRun linting:\n\n```\nnpm run lint\n```\n\nFix linting issues automatically:\n\n```\nnpm run format\n```\n\n## Benchmark\n\nTo run a benchmark to compare the performance with the native `JSON` parser:\n\n```\nnpm run benchmark\n```\n\n(Spoiler: `lossless-json` is much slower than native)\n\n## Build\n\nTo build a bundled and minified library (ES5), first install the dependencies once:\n\n```\nnpm install\n```\n\nThen bundle the code:\n\n```\nnpm run build\n```\n\nThis will generate an ES module output and an UMD bundle in the folder `./.lib` which can be executed in browsers and node.js and used in the browser.\n\n### Release\n\nTo release a new version:\n\n```\n$ npm run release\n```\n\nThis will:\n\n- lint\n- test\n- build\n- increment the version number\n- push the changes to git, add a git version tag\n- publish the npm package\n\nTo try the build and see the change list without actually publishing:\n\n```\n$ npm run release-dry-run\n```\n\n## License\n\nReleased under the [MIT license](LICENSE.md).\n","publish_time":1792144569421,"_cnpm_publish_time":1792144569421,"dist-tags":{"latest":"4.3.3"}}