{"name":"lossless-json","version":"2.0.2","keywords":["json","lossless","parse","stringify","long","bigint","bignumber","number","date","safe"],"author":{"name":"Jos de Jong"},"license":"MIT","_id":"lossless-json@2.0.2","maintainers":[{"name":"josdejong","email":"wjosdejong@gmail.com"}],"homepage":"https://github.com/josdejong/lossless-json#readme","bugs":{"url":"https://github.com/josdejong/lossless-json/issues"},"dist":{"shasum":"99b0d380f293e5e1c52d154f2656a1b3d0aceb6b","tarball":"http://registry-npm.ywwl.com/lossless-json/download/lossless-json-2.0.2.tgz","fileCount":48,"integrity":"sha512-lDh7OFGH0AfKlKmvbKLDIGlxdWl/5/ClZ4RaT7Zja3wraA3ynxWgZU6iD049eTcoyRJMHTekHqsOCFFWjTH6Cg==","signatures":[{"sig":"MEUCIG/WGqIzw1jCC+InuzdD4MbnXGMigNzz/Mj2WVicky8kAiEAvSShnVOtakJqJqrLIowfFCNFXWz6GRAtFCjGzuIBhZs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":160994,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjdiQYACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq4YA/+Oq+Z1pitda5e6sI2aDf4SRHdl6KXJIFRvQzZHToMDqVMmb9N\r\nWQj/AjP4WYvbirvDLRGTc4WhOJnf4Xg7biHN+QLif0Bn3h+crzS3VumB1qRW\r\nUG5srCid5cGGqi8qCtg9d2fMjuP691kwq6hkr/yAMFbZYBqxdoYpqso1Kycp\r\n3AcYyLxq1dLH3qx3PUXYn8AVOUFC1Ahik0WUpgvTVRMsenv3okxdZAQJIfEr\r\nnSFx5n87UV9g3MauwYGCYJ48UwWNJ+/IG6IUHr9zbOy/ax6DHk7eIPGhAaV5\r\nmpk2Y0TB/WTD+w3+aO0rVBBrR3V3dAUAY9lZNHMP6ugC3Xe0SzkkyWxHXnYn\r\nlXNpxfWrKcPfk95pnocqQ0rR/qUxX/i0oZtAjKkN7h9xfm2n37CL8tnS8ALJ\r\nVRoJNi0q6AFk5iEcrVeoNWVHWYx7QIRReLr4cBRGa4hKt9igYPFMpaObwWAX\r\nCm4EeyCjrkMlMKjlPELz2VAtoedlI362GPDzQW4VwddJzgB4BrsWs3y9fBn9\r\nUwZonXgVoLfH7DeH71Vff8viah7fXBObw21II6s86MBNTsksckt/dfOA/PQa\r\ndQR64F+LjOUBCOBUTMyPyVYhpiuS+nd4EHbe3hWr2l28mGZCTKFTM0nS6ZmO\r\nNCdWR6VwVBhKaWMHvyZWnwZzIfY1l8khnyI=\r\n=slmo\r\n-----END PGP SIGNATURE-----\r\n","size":45330,"noattachment":false,"key":"/lossless-json/-/lossless-json-2.0.2.tgz"},"main":"lib/esm/index.js","type":"module","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":"94d906cf255123e82a57b44bcc6ed0c6923599ec","scripts":{"lint":"prettier --ignore-path .gitignore lib --check . && eslint src/**/*.ts test/**/*.ts test-lib/**/*.mjs tools/**/*.mjs","test":"jest --rootDir=test","build":"npm-run-all build:**","format":"prettier --ignore-path .gitignore lib --write . && npm run lint -- --fix","test:lib":"npm run build && jest --rootDir='test-lib'","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.js && cpy tools/cjs/package.json lib/umd --flat","build:clean":"del-cli lib","build:types":"tsc --project tsconfig-types.json","build-and-test":"npm run build && jest && npm run lint","prepublishOnly":"npm test && npm run build"},"_npmUser":{"name":"josdejong","email":"wjosdejong@gmail.com"},"repository":{"url":"git+https://github.com/josdejong/lossless-json.git","type":"git"},"_npmVersion":"8.19.2","description":"Parse JSON without risk of losing numeric information","directories":{},"sideEffects":false,"_nodeVersion":"18.12.1","_hasShrinkwrap":false,"devDependencies":{"jest":"29.3.1","eslint":"8.27.0","rollup":"3.3.0","cpy-cli":"4.2.0","del-cli":"5.0.0","ts-jest":"29.0.3","prettier":"2.7.1","benchmark":"2.1.4","@babel/cli":"7.19.3","decimal.js":"10.4.2","typescript":"4.8.4","@babel/core":"7.20.2","@types/jest":"29.2.3","npm-run-all":"4.1.5","eslint-plugin-n":"15.5.1","@types/benchmark":"2.1.2","@babel/preset-env":"7.20.2","eslint-plugin-node":"11.1.0","eslint-plugin-import":"2.26.0","@rollup/plugin-terser":"0.1.0","eslint-plugin-promise":"6.1.1","eslint-config-standard":"17.0.0","@babel/preset-typescript":"7.18.6","@typescript-eslint/parser":"5.43.0","@typescript-eslint/eslint-plugin":"5.43.0","@babel/plugin-transform-typescript":"7.20.2"},"_npmOperationalInternal":{"tmp":"tmp/lossless-json_2.0.2_1668686872123_0.3145857445163833","host":"s3://npm-registry-packages"},"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":1668686872272,"_cnpm_publish_time":1668686872272,"dist-tags":{"latest":"4.3.3"}}