npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@danor-lib/json-bigint

v2.0.3

Published

JSON parse and stringify with native BigInt and ESM support in modern JavaScript

Downloads

437

Readme

[!TIP] 本文档由 AI 阅读代码后生成。中文版本已经过本人初步审校。英文版本基于中文版本由 AI 翻译生成。如有问题或更好的文档,欢迎提交 Issue。
This document is generated by AI after reading the code. The Chinese version has been preliminarily reviewed by the author. The English version is AI-translated based on the Chinese version. If you have any issues or a better version of the documentation, please feel free to submit an Issue.

简体中文 | English

@danor-lib/json-bigint

Version License

一个轻量级的 JSON 解析与序列化库,原生支持 BigInt。 A lightweight JSON parser and serializer with native BigInt support.

重构自sidorares/json-bigint

基础示例

import { parse, stringify } from '@danor-lib/json-bigint';

const input = '{"big":9223372036854775807}';
const object = parse(input);

console.log(typeof object.big); // 'bigint'
console.log(object.big.toString()); // '9223372036854775807'

const output = stringify(object);
console.log(output); // '{"big":9223372036854775807}'

静态方法

parse(text, reviver?, option?)

将 JSON 字符串解析为 JavaScript 值。该函数会自动识别超出安全整数范围的整数,并将其转换为 BigInt

  • 参数:
    • text {string} - 要解析的 JSON 文本。
    • reviver {function} 可选 - 与原生 JSON.parse 相同的转换器函数。
    • option {ParseOption} 可选 - 解析选项。

ParseOption说明 | 属性 | 类型 | 默认 | 描述 | | --------------------- | ----------------------------------- | --------- | --------------------------------------------------------- | | preferParseAsBigInt | boolean | false | 对安全整数范围内的数字也优先解析为 BigInt。 | | preferBigIntString | boolean | false | 对超出安全整数范围的数字返回原始字符串,而不是 BigInt。 | | protoAction | 'error' \| 'ignore' \| 'preserve' | 'error' | 解析对象键名为 __proto__ 时的处理方式。 | | constructorAction | 'error' \| 'ignore' \| 'preserve' | 'error' | 解析对象键名为 constructor 时的处理方式。 |

stringify(value, replacer?, space?)

将 JavaScript 值序列化为 JSON 字符串。支持 BigInt 类型,并保留 toJSONreplacer 以及缩进选项。

  • 参数:
    • value {any} - 要序列化的值。
    • replacer {function|Array} 可选 - 与原生 JSON.stringify 相同的替换器。
    • space {string|number} 可选 - 缩进空格数或缩进字符串。

错误代码

| 代码 | 位置 | 描述 | 上下文数据 | | ------------------------------------- | --------------------------------- | ------------------------------------------------------------------------ | ----------------------------- | | invalid-type-option-protoAction | json-bigint/parse(3:options) | protoAction 选项值无效,仅允许 'error' 'ignore' 'preserve' | { protoAction, option } | | invalid-type-option-constructorAction | json-bigint/parse(3:options) | constructorAction 选项值无效,仅允许 'error' 'ignore' 'preserve' | { constructorAction, option } | | contain-forbidden-prototype | json-bigint/parse | 对象包含禁止的 __proto__ 键 | { key, index } | | contain-forbidden-constructor | json-bigint/parse | 对象包含禁止的 constructor 键 | { key, index } | | bad-number | json-bigint/parse | 数字格式无效或为非有限数 | { string, index } | | bad-string | json-bigint/parse | 字符串格式无效(缺少闭合引号或转义错误) | { string, index } | | bad-array | json-bigint/parse | 数组格式无效 | { string, index } | | bad-object | json-bigint/parse | 对象格式无效 | { string, index } | | unexpected-char | json-bigint/parse | 解析时期望匹配某个字符但遇到了其他字符 | { char, index, charExpected } | | unexpected-word | json-bigint/parse | 遇到无法识别的字面量标记 | { char, index } | | invalid-replacer | json-bigint/stringify(2:replacer) | replacer 参数类型无效(必须为函数或数组) | { value } |