{"name":"token-types","version":"6.0.2","keywords":["token","integer","unsigned","numeric","float","IEEE","754","strtok3"],"author":{"url":"https://github.com/Borewit","name":"Borewit"},"license":"MIT","_id":"token-types@6.0.2","maintainers":[{"name":"borewit","email":"borewit@xs4all.nl"}],"homepage":"https://github.com/Borewit/token-types#readme","bugs":{"url":"https://github.com/Borewit/token-types/issues"},"dist":{"shasum":"103077415fb33191a1eff670f7ccd02637c48d9f","tarball":"http://registry-npm.ywwl.com/token-types/download/token-types-6.0.2.tgz","fileCount":5,"integrity":"sha512-p04i+HzAr5Ro1ZBPwE03gf948+F2bwxXNa4xqNy5Z9iHlcWravI1u8lmEW2q0Dg0NKErOHM1OcybFV5UtJ2I4Q==","signatures":[{"sig":"MEUCIG23zh1636tReV988VXnz8fqXmfdvvFz+b1k5hIp4EQaAiEAzW3xeXNxl3h4jNdGOhrAxOVW9q1azK3NRDjmSIBUJZE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23171,"size":5444,"noattachment":false,"key":"/token-types/-/token-types-6.0.2.tgz"},"type":"module","types":"lib/index.d.ts","engines":{"node":">=14.16"},"exports":"./lib/index.js","funding":{"url":"https://github.com/sponsors/Borewit","type":"github"},"gitHead":"6bccea0241ea59a3e6eeb604ad0ef32bed9b205d","scripts":{"lint":"npm run lint:md && npm run lint:ts","test":"mocha","build":"npm run compile","clean":"del-cli 'lib/**/*.js' 'lib/***.js.map' 'test/**/*.d.ts' 'test/**/*.js' 'test/**/*.js.map'","compile":"npm run compile-src && npm run compile-test","lint:md":"remark -u preset-lint-recommended .","lint:ts":"biome check","compile-src":"tsc --p lib","send-codacy":"c8 report --reports-dir=./.coverage --reporter=text-lcov | codacy-coverage","compile-test":"tsc --p test","test-coverage":"c8 npm run test"},"_npmUser":{"name":"borewit","actor":{"name":"borewit","type":"user","email":"borewit@xs4all.nl"},"email":"borewit@xs4all.nl"},"repository":{"url":"git+https://github.com/Borewit/token-types.git","type":"git"},"_npmVersion":"10.9.2","description":"Common token types for decoding and encoding numeric and string values","directories":{},"_nodeVersion":"22.17.0","dependencies":{"ieee754":"^1.2.1","@tokenizer/token":"^0.3.0"},"remarkConfig":{"plugins":["preset-lint-recommended"]},"_hasShrinkwrap":false,"packageManager":"yarn@4.9.2","devDependencies":{"c8":"^10.1.2","chai":"^5.2.0","mocha":"^11.7.1","del-cli":"^5.0.0","ts-node":"^10.9.1","remark-cli":"^12.0.1","typescript":"^5.8.3","@types/chai":"^5.2.2","@types/node":"^24.0.7","@types/mocha":"^10.0.0","@biomejs/biome":"^2.0.6","source-map-support":"^0.5.21","remark-preset-lint-recommended":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/token-types_6.0.2_1751178704531_0.9010312681429995","host":"s3://npm-registry-packages-npm-production"},"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)\r\n[![NPM version](https://badge.fury.io/js/token-types.svg)](https://npmjs.org/package/token-types)\r\n[![npm downloads](http://img.shields.io/npm/dm/token-types.svg)](https://npmcharts.com/compare/token-types,strtok3?start=1200&interval=30)\r\n[![coveralls](https://coveralls.io/repos/github/Borewit/token-types/badge.svg?branch=master)](https://coveralls.io/github/Borewit/token-types?branch=master)\r\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4723ce4613fc49cda8db5eed29f18834)](https://www.codacy.com/app/Borewit/token-types?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Borewit/token-types&amp;utm_campaign=Badge_Grade)\r\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)\r\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)\r\n\r\n# token-types\r\n\r\nA primitive token library used to read and write from a `Uint8Array`.\r\nAlthough it is possible to use this module directly, it is primarily designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).\r\n\r\n## Compatibility\r\n\r\nModule: version 5 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\r\nJavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm install --save token-types\r\n```\r\nUsually in combination with [strtok3](https://github.com/Borewit/strtok3):\r\n```sh\r\nnpm install --save strtok3\r\n```\r\n\r\nUsing TypeScript you should also install [@tokenizer/token](https://github.com/Borewit/tokenizer-token) as a development\r\ndependency:\r\n\r\n```shell\r\nnpm install --save-dev @tokenizer/token\r\n```\r\n\r\n\r\n## Example\r\n\r\n```js\r\nimport * as strtok3 from 'strtok3';\r\nimport * as token from 'token-types';\r\n\r\n(async () => {\r\n\r\n  const tokenizer = await strtok3.fromFile(\"somefile.bin\");\r\n  try {\r\n    const myNumber = await tokenizer.readToken(token.Float32_BE);\r\n    console.log(`My number: ${myNumber}`);\r\n  } finally {\r\n    tokenizer.close(); // Close the file\r\n  }\r\n})();\r\n```\r\n\r\n## Tokens\r\n\r\n### Numeric tokens\r\n\r\n`token-types` supports a wide variety of numeric tokens out of the box:\r\n\r\n| Token         | Number           | Bits | Endianness     |\r\n|---------------|------------------|------|----------------|\r\n| `UINT8`       | Unsigned integer |    8 | n/a            |\r\n| `UINT16_BE`   | Unsigned integer |   16 | big endian     |\r\n| `UINT16_LE`   | Unsigned integer |   16 | little endian  |\r\n| `UINT24_BE`   | Unsigned integer |   24 | big endian     |\r\n| `UINT24_LE`   | Unsigned integer |   24 | little endian  |\r\n| `UINT32_BE`   | Unsigned integer |   32 | big endian     |\r\n| `UINT32_LE`   | Unsigned integer |   32 | little endian  |\r\n| `UINT64_BE`   | Unsigned integer |   64 | big endian     |\r\n| `UINT64_LE`*  | Unsigned integer |   64 | little endian  |\r\n| `INT8`        | Signed integer   |    8 | n/a            |\r\n| `INT16_BE`    | Signed integer   |   16 | big endian     |\r\n| `INT16_LE`    | Signed integer   |   16 | little endian  |\r\n| `INT24_BE`    | Signed integer   |   24 | big endian     |\r\n| `INT24_LE`    | Signed integer   |   24 | little endian  |\r\n| `INT32_BE`    | Signed integer   |   32 | big endian     |\r\n| `INT32_LE`    | Signed integer   |   32 | little endian  |\r\n| `INT64_BE`    | Signed integer   |   64 | big endian     |\r\n| `INT64_LE`*   | Signed integer   |   64 | little endian  |\r\n| `Float16_BE`  | IEEE 754 float   |   16 | big endian     |\r\n| `Float16_LE`  | IEEE 754 float   |   16 | little endian  |\r\n| `Float32_BE`  | IEEE 754 float   |   32 | big endian     |\r\n| `Float32_LE`  | IEEE 754 float   |   32 | little endian  |\r\n| `Float64_BE`  | IEEE 754 float   |   64 | big endian     |\r\n| `Float64_LE`  | IEEE 754 float   |   64 | little endian  |\r\n| `Float80_BE`* | IEEE 754 float   |   80 | big endian     |\r\n| `Float80_LE`* | IEEE 754 float   |   80 | little endian  |\r\n\r\n(*) The tokens exceed the JavaScript IEEE 754 64-bit Floating Point precision, decoding and encoding is best effort based.\r\n\r\n### String tokens\r\n\r\nStringType decoding is using [@borewit/text-codec](https://github.com/Borewit/text-codec).\r\n\r\n### Custom tokens\r\n\r\nCustom tokens can be added, suitable for reading binary files or network messages:\r\n```js\r\n  ExtendedHeader = {\r\n    len: 10,\r\n\r\n    get: (buf, off) => {\r\n      return {\r\n        // Extended header size\r\n        size: Token.UINT32_BE.get(buf, off),\r\n        // Extended Flags\r\n        extendedFlags: Token.UINT16_BE.get(buf, off + 4),\r\n        // Size of padding\r\n        sizeOfPadding: Token.UINT32_BE.get(buf, off + 6),\r\n        // CRC data present\r\n        crcDataPresent: common.strtokBITSET.get(buf, off + 4, 31)\r\n      };\r\n    }\r\n  };\r\n```\r\n\r\n## Licence\r\n\r\nThis project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.\r\n","publish_time":1751178704749,"_cnpm_publish_time":1751178704749,"dist-tags":{"cjs":"4.2.1","esm":"5.0.0-alpha.3","latest":"6.2.0"}}