|
3 | 3 | [](https://npmjs.org/package/token-types) |
4 | 4 | [](https://david-dm.org/Borewit/token-types) |
5 | 5 | [](https://coveralls.io/github/Borewit/token-types?branch=master) |
6 | | -[](https://nodesecurity.io/orgs/borewit/projects/a193313e-00be-4611-bcba-f68773e5704c) |
| 6 | +[](https://www.codacy.com/app/Borewit/token-types?utm_source=github.com&utm_medium=referral&utm_content=Borewit/token-types&utm_campaign=Badge_Grade) |
| 7 | +[](https://snyk.io/test/github/Borewit/token-types?targetFile=package.json) |
7 | 8 |
|
8 | 9 | A primitive token library used to read from, and to write a node `Buffer`. |
9 | 10 |
|
10 | 11 | ### Tokens |
11 | 12 |
|
12 | 13 | `node-strtok` supports a wide variety of numerical tokens out of the box: |
13 | 14 |
|
14 | | -* `UINT8` |
15 | | -* `UINT16_BE`, `UINT16_LE` |
16 | | -* `UINT24_BE`, `UINT24_LE` |
17 | | -* `UINT32_BE`, `UINT32_LE` |
18 | | -* `UINT64_BE`, `UINT64_LE` * |
19 | | -* `INT8` |
20 | | -* `INT16_BE`, `INT16_LE` |
21 | | -* `INT24_BE`, `INT24_LE` |
22 | | -* `INT32_BE`, `INT32_LE` |
23 | | -* `INT64_BE`, `UINT64_LE` * |
| 15 | +* `UINT8` |
| 16 | +* `UINT16_BE`, `UINT16_LE` |
| 17 | +* `UINT24_BE`, `UINT24_LE` |
| 18 | +* `UINT32_BE`, `UINT32_LE` |
| 19 | +* `UINT64_BE`, `UINT64_LE`* |
| 20 | +* `INT8` |
| 21 | +* `INT16_BE`, `INT16_LE` |
| 22 | +* `INT24_BE`, `INT24_LE` |
| 23 | +* `INT32_BE`, `INT32_LE` |
| 24 | +* `INT64_BE`, `UINT64_LE`* |
24 | 25 |
|
25 | 26 | String types: |
26 | | -* Windows-1252 |
27 | | -* ISO-8859-1 |
28 | | - |
29 | | -*) The 64-bit tokens are best effort based, since JavaScript limit value size to less than 2^64. |
30 | | - |
31 | | -[npm-url]: https://npmjs.org/package/token-types |
32 | | -[npm-image]: https://badge.fury.io/js/token-types.svg |
33 | | -[npm-downloads-image]: http://img.shields.io/npm/dm/token-types.svg |
34 | | - |
35 | | -[travis-url]: https://travis-ci.org/Borewit/token-types |
36 | | -[travis-image]: https://api.travis-ci.org/Borewit/token-types.svg?branch=master |
37 | | - |
38 | | -[coveralls-url]: https://coveralls.io/github/Borewit/token-types?branch=master |
39 | | -[coveralls-image]: https://coveralls.io/repos/github/Borewit/token-types/badge.svg?branch=master |
| 27 | +* Windows-1252 |
| 28 | +* ISO-8859-1 |
| 29 | + |
| 30 | +*) The 64-bit tokens are best effort based, since JavaScript limit value size to less than 2^64. |
| 31 | + |
| 32 | +Complex tokens can be added, which makes very suitable for reading binary files or network messages: |
| 33 | +```JavaScript |
| 34 | + public static ExtendedHeader: Token.IGetToken<IExtendedHeader> = { |
| 35 | + len: 10, |
| 36 | + |
| 37 | + get: (buf, off): IExtendedHeader => { |
| 38 | + return { |
| 39 | + // Extended header size |
| 40 | + size: Token.UINT32_BE.get(buf, off), |
| 41 | + // Extended Flags |
| 42 | + extendedFlags: Token.UINT16_BE.get(buf, off + 4), |
| 43 | + // Size of padding |
| 44 | + sizeOfPadding: Token.UINT32_BE.get(buf, off + 6), |
| 45 | + // CRC data present |
| 46 | + crcDataPresent: common.strtokBITSET.get(buf, off + 4, 31) |
| 47 | + }; |
| 48 | + } |
| 49 | + }; |
| 50 | +``` |
0 commit comments