{"id":24395315,"url":"https://github.com/janispritzkau/nbt-ts","last_synced_at":"2025-04-11T15:04:18.712Z","repository":{"id":45388334,"uuid":"200808578","full_name":"janispritzkau/nbt-ts","owner":"janispritzkau","description":"An easy to use encoder and decoder for the NBT format","archived":false,"fork":false,"pushed_at":"2023-11-16T17:19:25.000Z","size":63,"stargazers_count":27,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T11:11:17.518Z","etag":null,"topics":["decoder","encoder","javascript","minecraft","nbt","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janispritzkau.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2019-08-06T08:23:09.000Z","updated_at":"2024-08-16T02:19:30.000Z","dependencies_parsed_at":"2023-11-16T18:49:04.517Z","dependency_job_id":null,"html_url":"https://github.com/janispritzkau/nbt-ts","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janispritzkau%2Fnbt-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janispritzkau%2Fnbt-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janispritzkau%2Fnbt-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janispritzkau%2Fnbt-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janispritzkau","download_url":"https://codeload.github.com/janispritzkau/nbt-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119401,"owners_count":21050754,"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":["decoder","encoder","javascript","minecraft","nbt","typescript"],"created_at":"2025-01-19T20:27:05.876Z","updated_at":"2025-04-11T15:04:18.666Z","avatar_url":"https://github.com/janispritzkau.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nbt-ts\n\n\u003e **⚠️ This library has not been maintained for some time. Please use it with caution or switch to another implementation!**\n\n[![npm](https://img.shields.io/npm/v/nbt-ts.svg)](https://www.npmjs.com/package/nbt-ts)\n[![downloads](https://img.shields.io/npm/dm/nbt-ts.svg)](https://www.npmjs.com/package/nbt-ts)\n\nAn easy to use encoder and decoder for the [NBT format](https://wiki.vg/NBT).\n\nNBT compound tags are represented as plain JavaScript objects. The `Byte`, `Short`,\n`Int` and `Float` number types are wrapped in custom classes since JavaScript\ndoes not support them directly.\n\nNode 10.4 or higher is required for BigInts, which are used to represent 64 bit integers.\n\n## Usage\n\n```js\nconst { encode, decode, Byte, Short, Int, Float } = require(\"nbt-ts\")\n\nconst buffer = encode(\"root\", {\n    byte: new Byte(-1),\n    short: new Short(65535),\n    int: new Int(-2147483648),\n    long: 0x7fffffffffffffffn,\n    float: new Float(0.75),\n    double: 0.1 + 0.2,\n    string: \"Hello world\",\n    list: [\"item 1\", \"item 2\"],\n    compound: {\n        byteArray: Buffer.from([0x80, 0x40, 0x20]),\n        // Int8Array does work here too\n        intArray: new Int32Array([1, 2, 3, 4]),\n        longArray: new BigInt64Array([1n, 2n, 3n, 4n])\n    },\n})\n\ndecode(Buffer.from(\"02000973686F7274546573747FFF\", \"hex\"))\n// → { name: 'shortTest', value: Short { value: 32767 }, length: 14 }\n\n// Encode unnamed tag\nencode(null, \"a\")\n// → \u003cBuffer 08 00 01 61\u003e\n\n// Decode unnamed tag\ndecode(Buffer.from(\"08000161\", \"hex\"), { unnamed: true })\n// → { name: null, value: 'a', length: 4 }\n```\n\nNote that the `encode` function accepts both unsigned numbers such as `255` and signed\nnumbers like `-1` which are essentially the same in the case of a 8 bit integer.\nHowever when decoded, they will always have the signed representation. If you want\nto convert a number to the unsigned representation, you might do something like this:\n\n```js\nvalue \u0026 0xff   // for bytes\nvalue \u0026 0xffff // for shorts\nvalue \u003e\u003e\u003e 0    // for ints\nBigInt.asUintN(64, value) // for longs\n// or\nvalue \u0026 0xffffffffffffffffn\n```\n\n## SNBT\n\nThe NBT format also has a more user-friendly variant in plain text. This format\nis referred to as **SNBT**, short for **stringified NBT**.\nHere are all the types represented in SNBT:\n\n```\n{\n    byte: 1b, short: 1s, int: 1, long: 1l,\n    float: 0.5f, double: 0.5,\n    string: \"Hello world\",\n    list: [{}, {}],\n    compound: {\n        byteArray: [B; 128, 64, 32],\n        intArray: [I; 1, 2, 3, 4],\n        longArray: [L; 1, 2, 3, 4]\n    }\n}\n```\n\nHere is an example how you can stringify or parse SNBT:\n\n```js\nconst { stringify, parse } = require(\"nbt-ts\")\n\nconst tag = parse(`{'Flying' :1b , unquoted: hello} `)\n// → { Flying: Byte { value: 1 }, unquoted: 'hello' }\n\nstringify(tag)\n// → '{Flying:1b,unquoted:\"hello\"}'\n```\n\n## Related projects\n\n- [`mc-chat-format`](https://github.com/janispritzkau/mc-chat-format).\n    Converts and formats Minecraft's JSON Chat components.\n- [`mcproto`](https://github.com/janispritzkau/mcproto) (Minecraft protocol implementation)\n- [`rcon-client`](https://github.com/janispritzkau/rcon-client)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanispritzkau%2Fnbt-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanispritzkau%2Fnbt-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanispritzkau%2Fnbt-ts/lists"}