token-types
Advanced tools
+1
-3
@@ -128,7 +128,5 @@ import type { IToken, IGetToken } from '@tokenizer/token'; | ||
| len: number; | ||
| private decoder; | ||
| private static readonly win1252Map; | ||
| private textDecoder; | ||
| constructor(len: number, encoding?: string); | ||
| get(data: Uint8Array, offset?: number): string; | ||
| private static decodeWindows1252; | ||
| } | ||
@@ -135,0 +133,0 @@ /** |
+3
-19
| import * as ieee754 from 'ieee754'; | ||
| import { TextDecoder } from "@kayahr/text-encoding"; | ||
| // Primitive types | ||
@@ -385,26 +386,9 @@ function dv(array) { | ||
| this.len = len; | ||
| if (encoding && encoding.toLowerCase() === 'windows-1252') { | ||
| this.decoder = StringType.decodeWindows1252; | ||
| } | ||
| else { | ||
| const textDecoder = new TextDecoder(encoding); | ||
| this.decoder = (bytes) => textDecoder.decode(bytes); | ||
| } | ||
| this.textDecoder = new TextDecoder(encoding); | ||
| } | ||
| get(data, offset = 0) { | ||
| const bytes = data.subarray(offset, offset + this.len); | ||
| return this.decoder(bytes); | ||
| return this.textDecoder.decode(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'; | ||
| /** | ||
@@ -411,0 +395,0 @@ * ANSI Latin 1 String using Windows-1252 (Code Page 1252) |
+0
-0
@@ -0,0 +0,0 @@ The MIT License (MIT) |
+5
-4
| { | ||
| "name": "token-types", | ||
| "version": "6.0.4", | ||
| "version": "6.1.0", | ||
| "description": "Common token types for decoding and encoding numeric and string values", | ||
@@ -46,6 +46,6 @@ "author": { | ||
| "devDependencies": { | ||
| "@biomejs/biome": "2.1.2", | ||
| "@biomejs/biome": "2.1.4", | ||
| "@types/chai": "^5.2.2", | ||
| "@types/mocha": "^10.0.10", | ||
| "@types/node": "^24.1.0", | ||
| "@types/node": "^24.2.1", | ||
| "c8": "^10.1.3", | ||
@@ -59,5 +59,6 @@ "chai": "^5.2.1", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "^5.8.3" | ||
| "typescript": "^5.9.2" | ||
| }, | ||
| "dependencies": { | ||
| "@kayahr/text-encoding": "^2.0.1", | ||
| "@tokenizer/token": "^0.3.0", | ||
@@ -64,0 +65,0 @@ "ieee754": "^1.2.1" |
+2
-3
@@ -94,6 +94,5 @@ [](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster) | ||
| 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. | ||
| StringType decoding is using [@kayahr/text-encoding](https://github.com/kayahr/text-encoding). | ||
| Check out [the MDN web docs for the TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding) for a complete list | ||
| Check out [Supported encodings](https://github.com/kayahr/text-encoding?tab=readme-ov-file#supported-encodings) for a complete list. | ||
@@ -100,0 +99,0 @@ ### Custom tokens |
22210
-4.67%3
50%539
-3.23%123
-0.81%+ Added
+ Added