token-types
Advanced tools
| The MIT License (MIT) | ||
| Copyright © 2025 Borewit | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
+9
-10
@@ -115,3 +115,3 @@ import type { IToken, IGetToken } from '@tokenizer/token'; | ||
| constructor(len: number); | ||
| get(array: Uint8Array, off: number): void; | ||
| get(_array: Uint8Array, _off: number): void; | ||
| } | ||
@@ -125,19 +125,18 @@ export declare class Uint8ArrayType implements IGetToken<Uint8Array> { | ||
| * Consume a fixed number of bytes from the stream and return a string with a specified encoding. | ||
| * Supports all encodings supported by TextDecoder, plus 'windows-1252'. | ||
| */ | ||
| export declare class StringType implements IGetToken<string> { | ||
| len: number; | ||
| encoding: string; | ||
| private textDecoder; | ||
| private decoder; | ||
| private static readonly win1252Map; | ||
| constructor(len: number, encoding: string); | ||
| get(uint8Array: Uint8Array, offset: number): string; | ||
| get(data: Uint8Array, offset?: number): string; | ||
| private static decodeWindows1252; | ||
| } | ||
| /** | ||
| * ANSI Latin 1 String | ||
| * Using windows-1252 / ISO 8859-1 decoding | ||
| * ANSI Latin 1 String using Windows-1252 (Code Page 1252) | ||
| * Windows-1252 is a superset of ISO 8859-1 / Latin-1. | ||
| */ | ||
| export declare class AnsiStringType implements IGetToken<string> { | ||
| len: number; | ||
| private textDecoder; | ||
| export declare class AnsiStringType extends StringType { | ||
| constructor(len: number); | ||
| get(uint8Array: Uint8Array, offset?: number): string; | ||
| } |
+27
-14
@@ -367,4 +367,3 @@ import * as ieee754 from 'ieee754'; | ||
| // ToDo: don't read, but skip data | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
| get(array, off) { | ||
| get(_array, _off) { | ||
| } | ||
@@ -382,2 +381,3 @@ } | ||
| * Consume a fixed number of bytes from the stream and return a string with a specified encoding. | ||
| * Supports all encodings supported by TextDecoder, plus 'windows-1252'. | ||
| */ | ||
@@ -387,21 +387,34 @@ export class StringType { | ||
| this.len = len; | ||
| this.encoding = encoding; | ||
| this.textDecoder = new TextDecoder(encoding); | ||
| if (encoding.toLowerCase() === 'windows-1252') { | ||
| this.decoder = StringType.decodeWindows1252; | ||
| } | ||
| else { | ||
| const textDecoder = new TextDecoder(encoding); | ||
| this.decoder = (bytes) => textDecoder.decode(bytes); | ||
| } | ||
| } | ||
| get(uint8Array, offset) { | ||
| return this.textDecoder.decode(uint8Array.subarray(offset, offset + this.len)); | ||
| get(data, offset = 0) { | ||
| const bytes = data.subarray(offset, offset + this.len); | ||
| return this.decoder(bytes); | ||
| } | ||
| static decodeWindows1252(bytes) { | ||
| let result = ''; | ||
| for (let i = 0; i < bytes.length; i++) { | ||
| const byte = bytes[i]; | ||
| result += byte < 0x80 || byte >= 0xA0 | ||
| ? String.fromCharCode(byte) | ||
| : StringType.win1252Map[byte - 0x80]; | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
| StringType.win1252Map = '\u20AC\u0081\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160\u2039\u0152\u008D\u017D\u008F\u0090\u2018\u2019\u201C\u201D\u2022\u2013\u2014\u02DC\u2122\u0161\u203A\u0153\u009D\u017E\u0178'; | ||
| /** | ||
| * ANSI Latin 1 String | ||
| * Using windows-1252 / ISO 8859-1 decoding | ||
| * ANSI Latin 1 String using Windows-1252 (Code Page 1252) | ||
| * Windows-1252 is a superset of ISO 8859-1 / Latin-1. | ||
| */ | ||
| export class AnsiStringType { | ||
| export class AnsiStringType extends StringType { | ||
| constructor(len) { | ||
| this.len = len; | ||
| this.textDecoder = new TextDecoder('windows-1252'); | ||
| super(len, 'windows-1252'); | ||
| } | ||
| get(uint8Array, offset = 0) { | ||
| return this.textDecoder.decode(uint8Array.subarray(offset, offset + this.len)); | ||
| } | ||
| } |
+13
-21
| { | ||
| "name": "token-types", | ||
| "version": "6.0.0", | ||
| "version": "6.0.1", | ||
| "description": "Common token types for decoding and encoding numeric and string values", | ||
@@ -14,3 +14,3 @@ "author": { | ||
| "scripts": { | ||
| "clean": "del-cli lib/**/*.js lib/***.js.map *.d.ts test/**/*.d.ts test/**/*.js test/**/*.js.map .nyc_output", | ||
| "clean": "del-cli 'lib/**/*.js' 'lib/***.js.map' 'test/**/*.d.ts' 'test/**/*.js' 'test/**/*.js.map'", | ||
| "build": "npm run compile", | ||
@@ -20,6 +20,5 @@ "compile-src": "tsc --p lib", | ||
| "compile": "npm run compile-src && npm run compile-test", | ||
| "eslint": "eslint lib/**/*.ts --ignore-pattern lib/**/*.d.ts test/**/*.ts", | ||
| "lint-ts": "tslint lib/index.ts --exclude '*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts,lib/**/*.d.ts'", | ||
| "lint-md": "remark -u preset-lint-recommended .", | ||
| "lint": "npm run lint-md && npm run eslint", | ||
| "lint:ts": "biome check", | ||
| "lint:md": "remark -u preset-lint-recommended .", | ||
| "lint": "npm run lint:md && npm run lint:ts", | ||
| "test": "mocha", | ||
@@ -48,18 +47,9 @@ "test-coverage": "c8 npm run test", | ||
| "devDependencies": { | ||
| "@types/chai": "^4.3.1", | ||
| "@types/chai": "^5.2.2", | ||
| "@types/mocha": "^10.0.0", | ||
| "@types/node": "^20.14.9", | ||
| "@typescript-eslint/eslint-plugin": "^7.14.1", | ||
| "@typescript-eslint/parser": "^7.14.1", | ||
| "@types/node": "^24.0.7", | ||
| "c8": "^10.1.2", | ||
| "chai": "^5.1.1", | ||
| "chai": "^5.2.0", | ||
| "del-cli": "^5.0.0", | ||
| "eslint": "^8.57.0", | ||
| "eslint-config-prettier": "^9.0.0", | ||
| "eslint-import-resolver-typescript": "^3.6.1", | ||
| "eslint-plugin-import": "^2.29.0", | ||
| "eslint-plugin-jsdoc": "^48.5.0", | ||
| "eslint-plugin-node": "^11.1.0", | ||
| "eslint-plugin-unicorn": "^54.0.0", | ||
| "mocha": "^10.0.0", | ||
| "mocha": "^11.7.1", | ||
| "remark-cli": "^12.0.1", | ||
@@ -69,5 +59,6 @@ "remark-preset-lint-recommended": "^7.0.0", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "^5.5.2" | ||
| "typescript": "^5.8.3" | ||
| }, | ||
| "dependencies": { | ||
| "@biomejs/biome": "^2.0.5", | ||
| "@tokenizer/token": "^0.3.0", | ||
@@ -90,3 +81,4 @@ "ieee754": "^1.2.1" | ||
| "strtok3" | ||
| ] | ||
| ], | ||
| "packageManager": "yarn@4.9.2" | ||
| } |
+6
-5
@@ -94,8 +94,5 @@ [](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster) | ||
| StringType decoding is implemented using TextDecoder which supports a large number of encodings including but not limited to: | ||
| StringType decoding is implemented using [TextDecoder](https://developer.mozilla.org/docs/Web/API/TextDecoder), | ||
| it has build-in support for [Windows-1252](https://en.wikipedia.org/wiki/Windows-1252) decoding. | ||
| * UTF-8 (the default) | ||
| * Windows-1252 | ||
| * ISO-8859-1 | ||
| Check out [the MDN web docs for the TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding) for a complete list | ||
@@ -124,1 +121,5 @@ | ||
| ``` | ||
| ## Licence | ||
| This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed. |
-7
| Copyright 2017 Borewit | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
23171
1.83%12
-42.86%557
2.2%124
0.81%3
50%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added