https://github.com/vikyd/json-bigint-single
Single file version of json-bigint.
https://github.com/vikyd/json-bigint-single
bigint js json-bigint large number
Last synced: 8 months ago
JSON representation
Single file version of json-bigint.
- Host: GitHub
- URL: https://github.com/vikyd/json-bigint-single
- Owner: vikyd
- License: mit
- Created: 2022-05-18T13:04:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-19T02:56:20.000Z (about 4 years ago)
- Last Synced: 2025-06-10T22:52:53.157Z (12 months ago)
- Topics: bigint, js, json-bigint, large, number
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-bigint-single
Single file version of [json-bigint](https://github.com/sidorares/json-bigint).
Suitable for single line situation, like Postman `Global Variable`.
# Install
Download directly from CDN:
- unpkg: https://unpkg.com/json-bigint-single@1.0.0/dist/json-bigint-single.var.min.js
- page: https://unpkg.com/browse/json-bigint-single@1.0.0/
Or by npm, yarn:
```sh
# npm
npm install json-bigint-single
# yarn
yarn add json-bigint-single
```
# Usage
## Used in Postman Script
In Postman-like Apps:
1. create new global variable:
- name: `lib-json-bigint`
- value: content of `dist/json-bigint-single.var.min.js`
2. in Postman script:
```js
// 9007199254740991 - Number.MAX_SAFE_INTEGER:
// 99999999999999998 - example bigger int
// example json string:
const respBodyStr = `{"a": 99999999999999998}`;
// load lib from global variable
eval(pm.globals.get("lib-json-bigint"));
// got variable: JsonBigInt
// usage: https://github.com/sidorares/json-bigint
const obj = JsonBigInt.parse(respBodyStr);
// before parse: {a: 99999999999999998}
// after parse : {a: "99999999999999998"}
// big int value becomes string
console.log(obj);
// need `.toString()` to get final string value
// otherwise got a special object
const strVal = obj.a.toString();
// postman assertion with string
pm.test("JSON value equals", function () {
pm.expect(strVal).to.eql("99999999999999998");
});
```
# Development
This repo is a webpack build project.
```sh
# clone
git clone https://github.com/vikyd/json-bigint-single.git
# get in
cd json-bigint-single
# install dependencies
npm install
# build dist
npm run build
```