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 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-bint

v0.0.8

Published

json with bigint supports.

Downloads

6

Readme

NPM version Downloads/month Conventional Commits

json-bint (json + bigint supports)

Why?

json-bint:一个专为解决 JSON 不支持 BigInt 类型的问题而设计的开源 npm 包。在许多应用程序中,BigInt 类型用于表示超出传统 JavaScript 数值范围的大整数,但是标准的 JSON 解析器无法直接处理这种类型。json-bint 正是为了填补这一缺失而诞生的。

json-bint 提供了一种简便的方式,可以在将 BigInt 值序列化为 JSON 字符串时,确保其信息不会丢失。同时,它还能够在解析 JSON 字符串时,将包含 BigInt 值的字段正确地转换为 JavaScript 中的 BigInt 类型,以便应用程序可以无缝处理这些数据。

Solution

json-bint 提供了一种简单的解决方案,以确保 BigInt 值在 JSON 序列化和解析过程中的完整性:

序列化(BigInt to JSON):在将包含 BigInt 值的对象序列化为 JSON 字符串时,json-bint 会将 BigInt 值转换为正确的数值,以避免信息丢失。这确保了在反序列化时能够正确还原 BigInt 值。

反序列化(JSON to BigInt):在解析 JSON 字符串时,json-bint 会检测到超出安全范围的整数,并将其转换回 JavaScript 中的 BigInt 类型,以确保数据的准确性。

Usage

$ npm i json-bint
import JBINT from 'json-bint'

JSON.parse('{"foo": 12345678901234567890}') // { foo: 12345678901234567000 }
JBINT.parse('{"foo": 12345678901234567890}') // { foo: 12345678901234567890n }

JSON.stringify({ foo: 12345678901234567890n }) // Uncaught TypeError: Do not know how to serialize a BigInt
JBINT.stringify({ foo: 12345678901234567890n }) // '{"foo": 12345678901234567890}'

Perf

TODO.

Credits:

Lisente

MIT