googleapis / googleapis/google-cloud-node
refactor!: Remove `json-bigint`
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
Remove `json-bigint` and `@types/json-bigint`.
We can use native `bigint`s via the JSON.parse [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) parameter and essentially check via:
```ts
const jsonParse = (stringified: string) => JSON.parse(stringified, (key, value, context) => {
if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
// Use the context for the appropriate precision
return BigInt(context.source);
}
return value;
});
```
Example:
```js
const bigJSON = '{"largeNumber": 12345678901234567890, "a": {"b": 1, "c": 893081290390128309213821903 }}';
const res = jsonParse(bigJSON);
// res:
// {
// largeNumber: 12345678901234567890n,
// a: { b: 1, c: 893081290390128309213821903n }
// }
```
Improves on:
- https://github.com/googleapis/gcp-metadata/pull/74
- https://github.com/googleapis/gcp-metadata/pull/152
Documentation:
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt#using_bigint_to_convert_a_number_to_a_bigint
- https://www.json.org/json-en.html
Contributor guide
Assessment
This issue has not been assessed yet.