{"id":19391831,"url":"https://github.com/joeltg/big-varint","last_synced_at":"2025-04-24T00:31:53.669Z","repository":{"id":92290720,"uuid":"381408756","full_name":"joeltg/big-varint","owner":"joeltg","description":"Encode and decode arbitrarily large signed and unsigned BigInts","archived":false,"fork":false,"pushed_at":"2024-10-17T19:05:29.000Z","size":376,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-17T13:16:03.695Z","etag":null,"topics":["bigint","biginteger","decoding","encoding","typescript","variable-length-encoding","varint"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joeltg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-29T15:14:23.000Z","updated_at":"2025-01-16T12:28:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0ea0008-6b47-4e3b-812f-323ac5f4732c","html_url":"https://github.com/joeltg/big-varint","commit_stats":{"total_commits":30,"total_committers":1,"mean_commits":30.0,"dds":0.0,"last_synced_commit":"65346e5688245b20f05e5ce2dd8c784eb3ae3e15"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fbig-varint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fbig-varint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fbig-varint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fbig-varint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeltg","download_url":"https://codeload.github.com/joeltg/big-varint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250539488,"owners_count":21447318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigint","biginteger","decoding","encoding","typescript","variable-length-encoding","varint"],"created_at":"2024-11-10T10:29:21.865Z","updated_at":"2025-04-24T00:31:49.173Z","avatar_url":"https://github.com/joeltg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeltg%2Fbig-varint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeltg%2Fbig-varint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeltg%2Fbig-varint/lists"}