{"name":"big-varint","version":"0.2.0","keywords":["bigint","varint","signed-varint"],"author":{"name":"Joel Gustafson"},"license":"MIT","_id":"big-varint@0.2.0","maintainers":[{"name":"joelg","email":"joelg@mit.edu"}],"homepage":"https://github.com/joeltg/big-varint#readme","bugs":{"url":"https://github.com/joeltg/big-varint/issues"},"dist":{"shasum":"f2478be4770517bee13a52b26340ebfb86aa36ed","tarball":"http://registry-npm.ywwl.com/big-varint/download/big-varint-0.2.0.tgz","fileCount":9,"integrity":"sha512-O9lHOxmiVVtFxxbMctGW2/ewRG610wOHx1seOtzyrQE/qiu7gvG9CdenYNT7CGdIxhIn6WLUy4wjsdk38aIdoQ==","signatures":[{"sig":"MEYCIQCY8weUfw+8oATd2SyemDoQj6KamekSY3aoFVF9y9ggqwIhALuJu+O9OaC3sQVgVhCeDJztMXBPEyQPPOVJtrSJPH5n","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8272,"size":3239,"noattachment":false,"key":"/big-varint/-/big-varint-0.2.0.tgz"},"main":"lib/index.js","type":"module","types":"lib/index.d.ts","exports":{".":"./lib/index.js","./signed":"./lib/signed.js","./unsigned":"./lib/unsigned.js"},"gitHead":"20a230d0ca16a0163fe6a07465640a5fde0723bf","scripts":{"dev":"tsc --build tsconfig.json test/tsconfig.json --watch","test":"ava","build":"tsc --build tsconfig.json test/tsconfig.json","clean":"tsc --build tsconfig.json test/tsconfig.json --clean"},"_npmUser":{"name":"joelg","email":"joelg@mit.edu"},"repository":{"url":"git+https://github.com/joeltg/big-varint.git","type":"git"},"_npmVersion":"10.8.3","description":"Encode and decode arbitrarily large signed and unsigned BigInts","directories":{},"_nodeVersion":"22.9.0","_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","typescript":"^5.6.3","@types/node":"^22.7.6","@ava/typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/big-varint_0.2.0_1729180449389_0.5616317821667121","host":"s3://npm-registry-packages"},"readme":"# big-varint\n\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg)](https://github.com/RichardLitt/standard-readme) [![license](https://img.shields.io/github/license/joeltg/big-varint)](https://opensource.org/licenses/MIT) [![NPM version](https://img.shields.io/npm/v/big-varint)](https://www.npmjs.com/package/big-varint) ![TypeScript types](https://img.shields.io/npm/types/big-varint)\n\nEncode and decode arbitrarily large signed and unsigned BigInts.\n\nThis library is TypeScript-native, ESM-only, and has zero dependencies. It uses Uint8Arrays and works in the browser, Node, and [Deno](https://deno.land/). It uses the same binary encoding as Go's [encoding/binary](https://pkg.go.dev/encoding/binary) module, the [Protobuf spec](https://developers.google.com/protocol-buffers/docs/encoding), and the [varint](https://www.npmjs.com/package/varint) / [signed-varint](https://www.npmjs.com/package/signed-varint) NPM packages.\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Testing](#testing)\n- [Credits](#credits)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\n```\nnpm i big-varint\n```\n\n## Usage\n\n### Encode a Signed Varint\n\n```ts\nimport { encode } from \"big-varint/signed\"\n\nconst i = -300n\n\nencode(i) // Uint8Array(2) [ 215, 4 ]\n```\n\n### Decode a Signed Varint\n\n```ts\nimport { decode } from \"big-varint/signed\"\n\nconst data = new Uint8Array([215, 4])\n\ndecode(data) // -300n\n```\n\n`decode` can also be passed an optional `offset` parameter:\n\n```ts\nimport { decode } from \"big-varint/signed\"\n\nconst data = new Uint8Array([0, 0, 215, 4, 37, 37, 37])\n\ndecode(data, 2) // -300n\n\n// The encoding length of the most recently decoded value\n// can be accessed via the `decode.bytes` property.\ndecode.bytes // 2\n```\n\n### Get the Encoding Length of a Signed Varint\n\n```ts\nimport { encodingLength } from \"big-varint/signed\"\n\nconst i = -300n\n\nencodingLength(i) // 2\n```\n\n### Encode an Unsigned Varint\n\n```ts\nimport encode from \"big-varint/unsigned\"\n\nconst i = 123456789012345678901234567890n\n\nencode(i)\n\n/*\nUint8Array(14) [\n  210, 149, 252, 241,\n  228, 157, 248, 185,\n  195, 237, 191, 200,\n  238,  49\n]\n*/\n```\n\n### Decode an Unsigned Varint\n\n```ts\nimport { decode } from \"big-varint/unsigned\"\n\nconst data = new Uint8Array([210, 149, 252, 241, 228, 157, 248, 185, 195, 237, 191, 200, 238, 49])\n\ndecode(data) // 123456789012345678901234567890n\n```\n\n`decode` can also be passed an optional `offset` parameter:\n\n```typescript\nimport { decode } from \"big-varint/unsigned\"\n\nconst data = new Uint8Array([\n\t0, 0, 0, 0, 210, 149, 252, 241, 228, 157, 248, 185, 195, 237, 191, 200, 238, 49, 37, 37, 0, 0,\n])\n\ndecode(data, 4) // 123456789012345678901234567890n\n\n// The encoding length of the most recently decoded value\n// can be accessed via the `decode.bytes` property.\ndecode.bytes // 14\n```\n\n### Get the Encoding Length of an Unsigned Varint\n\n```typescript\nimport { encodingLength } from \"big-varint/unsigned\"\n\nconst i = 123456789012345678901234567890n\n\nencodingLength(i) // 14\n```\n\n## Testing\n\nTests use [AVA](https://github.com/avajs/ava) and live in the [test](./test/) directory.\n\n```\nnpm run test\n```\n\n## Credits\n\nA previous version of this library was adapted from [chrisdickinson/varint](https://github.com/chrisdickinson/varint), but has since been rewritten from scratch.\n\n## Contributing\n\nI don't expect to add any additional functionality to this library, but am potentially open to proposals for better interfaces. Open issues to discuss any questions before making an PRs.\n\n## License\n\nMIT © 2021 Joel Gustafson\n","publish_time":1729180449598,"_cnpm_publish_time":1729180449598,"dist-tags":{"latest":"0.2.1"}}