{"_id":"token-types@6.2.0","bugs":{"url":"https://github.com/Borewit/token-types/issues"},"dist":{"shasum":"0c32d85bb7918555e20c9002f2abcd4e7fe74fa5","tarball":"http://registry-npm.ywwl.com/token-types/download/token-types-6.2.0.tgz","fileCount":5,"integrity":"sha512-s9euYHM//T3loJtbNUYdbAzsMlvKBeRS+XCLFy+UGosMQH19Hwjap5k19i4PPAEJJBsVIpMpVTxl4fIqCuNfUg==","signatures":[{"sig":"MEQCIHZbKUuPcivu3/7obgDSZW8ElISiUm1QvQVhCsrraseoAiBSdijqWI6ICVLeKglfAPQGFljFLdWWD9n7l99aqIQhXg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFeIOOi+ANXCuKUdECy2YMEJkyv3Iec6uDMw06aFYQR4AiBun8yQax0lBbZxEFq7Uc28hg770yMtnFJQ/ABo5sWjsg=="}],"unpackedSize":23853,"size":5651,"noattachment":false,"key":"/token-types/-/token-types-6.2.0.tgz"},"name":"token-types","type":"module","types":"dist/lib/index.d.ts","author":{"url":"https://github.com/Borewit","name":"Borewit"},"engines":{"node":">=14.16"},"exports":"./dist/lib/index.js","funding":{"url":"https://github.com/sponsors/Borewit","type":"github"},"gitHead":"0402b5c0bd59b3228e7b9c34cf610cab9d862062","license":"MIT","scripts":{"fix":"npm run lint:ts:fix","lint":"npm run lint:md && npm run lint:ts","test":"npm run typecheck && vitest run","build":"npm run clean && npm run compile:prod","clean":"del-cli dist coverage","compile":"tsc --project tsconfig.json","lint:md":"remark -u preset-lint-recommended .","lint:ts":"biome check","typecheck":"tsc --project tsconfig.test.json","test:watch":"vitest","lint:ts:fix":"biome check --write","compile:prod":"tsc --project tsconfig.prod.json","format:check":"biome format","update-biome":"yarn add -D --exact @biomejs/biome && npx @biomejs/biome migrate --write","test-coverage":"npm run typecheck && vitest run --coverage","prepublishOnly":"npm run build"},"version":"6.2.0","_npmUser":{"name":"borewit","email":"borewit@xs4all.nl"},"homepage":"https://github.com/Borewit/token-types#readme","keywords":["token","integer","unsigned","numeric","float","IEEE","754","strtok3"],"repository":{"url":"git+https://github.com/Borewit/token-types.git","type":"git"},"_npmVersion":"10.9.9","description":"Common token types for decoding and encoding numeric and string values","directories":{},"maintainers":[{"name":"borewit","email":"borewit@xs4all.nl"}],"_nodeVersion":"22.23.3","dependencies":{"ieee754":"^1.2.1","@tokenizer/token":"^0.3.0","@borewit/text-codec":"^0.2.3"},"remarkConfig":{"plugins":["preset-lint-recommended"]},"_hasShrinkwrap":false,"packageManager":"yarn@4.18.1","devDependencies":{"vite":"^8.3.5","vitest":"^5.0.5","del-cli":"^8.0.1","remark-cli":"^12.0.1","typescript":"^7.0.2","@types/node":"^26.6.6","@biomejs/biome":"2.6.4","@vitest/coverage-v8":"^5.0.5","remark-preset-lint-recommended":"^7.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/token-types_6.2.0_1793612478617_0.06808407778697101"},"readme":"[![Node.js CI](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml/badge.svg?branch=master)](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster)\n[![NPM version](https://badge.fury.io/js/token-types.svg)](https://npmjs.org/package/token-types)\n[![npm downloads](http://img.shields.io/npm/dm/token-types.svg)](https://npmcharts.com/compare/token-types,strtok3?start=1200&interval=30)\n[![codecov](https://codecov.io/gh/Borewit/token-types/branch/master/graph/badge.svg)](https://codecov.io/gh/Borewit/token-types)\n[![DeepScan grade](https://deepscan.io/api/teams/5165/projects/6940/branches/61852/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=6940&bid=61852)\n[![Known Vulnerabilities](https://snyk.io/test/github/Borewit/token-types/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/token-types?targetFile=package.json)\n\n# token-types\n\nA primitive token library used to read and write from a `Uint8Array`.\nAlthough it is possible to use this module directly, it is primarily designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).\n\n## Compatibility\n\nModule: version 5 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\nJavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).\n\nNode.js 18 is supported for running the published package; it is not a supported\nbuild environment. The test toolchain requires Node.js 22.12 or later. CI builds\non Node.js 24 and runs the tests on Node.js 22, 24 and 26.\n\n## Development\n\nUse Node.js 24 and the Yarn version pinned in `package.json` to install development\ndependencies and build from source:\n\n```sh\ncorepack enable\nyarn install --immutable\nyarn test\n```\n\n`yarn test` type-checks the sources and runs the Vitest suite against the\nTypeScript sources. `yarn test:watch` runs Vitest in watch mode, and\n`yarn test-coverage` writes text and LCOV reports to `coverage`. `yarn clean`\nremoves `dist` and coverage.\n\n`yarn lint` checks the Markdown and Biome rules. `yarn format:check` verifies\nBiome formatting, and `yarn fix` applies formatting, import organization and\nsafe lint fixes.\n\n## Installation\n\n```sh\nnpm install --save token-types\n```\nUsually in combination with [strtok3](https://github.com/Borewit/strtok3):\n```sh\nnpm install --save strtok3\n```\n\nUsing TypeScript you should also install [@tokenizer/token](https://github.com/Borewit/tokenizer-token) as a development\ndependency:\n\n```shell\nnpm install --save-dev @tokenizer/token\n```\n\n\n## Example\n\n```js\nimport * as strtok3 from 'strtok3';\nimport * as token from 'token-types';\n\n(async () => {\n\n  const tokenizer = await strtok3.fromFile(\"somefile.bin\");\n  try {\n    const myNumber = await tokenizer.readToken(token.Float32_BE);\n    console.log(`My number: ${myNumber}`);\n  } finally {\n    tokenizer.close(); // Close the file\n  }\n})();\n```\n\n## Tokens\n\n### Numeric tokens\n\n`token-types` supports a wide variety of numeric tokens out of the box:\n\n| Token         | Number           | Bits | Endianness     |\n|---------------|------------------|------|----------------|\n| `UINT8`       | Unsigned integer |    8 | n/a            |\n| `UINT16_BE`   | Unsigned integer |   16 | big endian     |\n| `UINT16_LE`   | Unsigned integer |   16 | little endian  |\n| `UINT24_BE`   | Unsigned integer |   24 | big endian     |\n| `UINT24_LE`   | Unsigned integer |   24 | little endian  |\n| `UINT32_BE`   | Unsigned integer |   32 | big endian     |\n| `UINT32_LE`   | Unsigned integer |   32 | little endian  |\n| `UINT64_BE`   | Unsigned integer |   64 | big endian     |\n| `UINT64_LE`*  | Unsigned integer |   64 | little endian  |\n| `INT8`        | Signed integer   |    8 | n/a            |\n| `INT16_BE`    | Signed integer   |   16 | big endian     |\n| `INT16_LE`    | Signed integer   |   16 | little endian  |\n| `INT24_BE`    | Signed integer   |   24 | big endian     |\n| `INT24_LE`    | Signed integer   |   24 | little endian  |\n| `INT32_BE`    | Signed integer   |   32 | big endian     |\n| `INT32_LE`    | Signed integer   |   32 | little endian  |\n| `INT64_BE`    | Signed integer   |   64 | big endian     |\n| `INT64_LE`*   | Signed integer   |   64 | little endian  |\n| `Float16_BE`  | IEEE 754 float   |   16 | big endian     |\n| `Float16_LE`  | IEEE 754 float   |   16 | little endian  |\n| `Float32_BE`  | IEEE 754 float   |   32 | big endian     |\n| `Float32_LE`  | IEEE 754 float   |   32 | little endian  |\n| `Float64_BE`  | IEEE 754 float   |   64 | big endian     |\n| `Float64_LE`  | IEEE 754 float   |   64 | little endian  |\n| `Float80_BE`* | IEEE 754 float   |   80 | big endian     |\n| `Float80_LE`* | IEEE 754 float   |   80 | little endian  |\n\n(*) The tokens exceed the JavaScript IEEE 754 64-bit Floating Point precision, decoding and encoding is best effort based.\n\n### String and byte tokens\n\n`StringType` decoding is using [@borewit/text-codec](https://github.com/Borewit/text-codec).\n\n`StringType` and `Uint8ArrayType` implement `IToken`, so the same fixed-size\ntoken can decode and encode:\n\n```js\nimport { StringType, Uint8ArrayType } from 'token-types';\n\nconst ascii = new StringType(4, 'ascii');\nconst buffer = new Uint8Array(8);\nascii.put(buffer, 0, 'fLaC');\n\nconst bytes = new Uint8ArrayType(4);\nbytes.put(buffer, 4, Uint8Array.from([1, 2, 3, 4]));\n```\n\n`put` rejects values whose byte length differs from `len`, so a fixed-size\nfield is never silently truncated or padded.\n\n### Custom tokens\n\nCustom tokens can be added, suitable for reading binary files or network messages:\n```js\n  ExtendedHeader = {\n    len: 10,\n\n    get: (buf, off) => {\n      return {\n        // Extended header size\n        size: Token.UINT32_BE.get(buf, off),\n        // Extended Flags\n        extendedFlags: Token.UINT16_BE.get(buf, off + 4),\n        // Size of padding\n        sizeOfPadding: Token.UINT32_BE.get(buf, off + 6),\n        // CRC data present\n        crcDataPresent: common.strtokBITSET.get(buf, off + 4, 31)\n      };\n    }\n  };\n```\n\n## Licence\n\nThis project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.\n","publish_time":1793612478706,"_cnpm_publish_time":1793612478706,"dist-tags":{"cjs":"4.2.1","esm":"5.0.0-alpha.3","latest":"6.2.0"}}