@ansi-tools/parser 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/escaped.js CHANGED
@@ -1,4 +1,4 @@
1
- import { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, CODE_TYPES, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, TOKEN_TYPES, parser } from "./parse-DBLatt5c.js";
1
+ import { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, CODE_TYPES, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, TOKEN_TYPES, parser } from "./parse-BCjxFvJh.js";
2
2
 
3
3
  //#region src/tokenize.escaped.ts
4
4
  const CSI_ESCAPED = "\\u009b";
@@ -155,7 +155,6 @@ function* tokenizer(input) {
155
155
  let terminator = "";
156
156
  let terminatorPos = -1;
157
157
  const pos = i;
158
- const code = currentCode;
159
158
  while (!terminator && i < l) {
160
159
  if (input.charCodeAt(i) === BACKSLASH) {
161
160
  const next = input[i + 1];
@@ -178,9 +177,9 @@ function* tokenizer(input) {
178
177
  }
179
178
  }
180
179
  if (terminator) break;
181
- if (code !== CSI && code !== ESC) {
180
+ if (currentCode !== CSI && currentCode !== ESC) {
182
181
  if (next === "a" && i + 2 <= l) {
183
- if (code === OSC && input[i + 1] === "a") {
182
+ if (currentCode === OSC && input[i + 1] === "a") {
184
183
  terminator = "\\a";
185
184
  terminatorPos = i;
186
185
  i += 2;
@@ -189,7 +188,7 @@ function* tokenizer(input) {
189
188
  if (i + 4 <= l) {
190
189
  const char3 = input[i + 2];
191
190
  const char4 = input[i + 3];
192
- if (char3 === "0" && char4 === "7" && code === OSC) {
191
+ if (char3 === "0" && char4 === "7" && currentCode === OSC) {
193
192
  terminator = "\\x07";
194
193
  terminatorPos = i;
195
194
  i += 4;
@@ -203,7 +202,7 @@ function* tokenizer(input) {
203
202
  i += 6;
204
203
  }
205
204
  }
206
- } else if (next === "u" && code === OSC && i + 6 <= l) {
205
+ } else if (next === "u" && currentCode === OSC && i + 6 <= l) {
207
206
  if (input[i + 2] === "0" && input[i + 3] === "0" && input[i + 4] === "0" && input[i + 5] === "7") {
208
207
  terminator = "\\u0007";
209
208
  terminatorPos = i;
@@ -235,28 +234,25 @@ function* tokenizer(input) {
235
234
  }
236
235
  }
237
236
  }
238
- } else if (code === CSI) {
237
+ } else if (currentCode === CSI) {
239
238
  const charCode = input.charCodeAt(i);
240
239
  if (charCode >= 64 && charCode <= 126) {
241
240
  terminator = input[i];
242
241
  terminatorPos = i;
243
242
  i++;
244
243
  }
245
- } else if (code === ESC) {
244
+ } else if (currentCode === ESC) {
246
245
  terminator = input[i];
247
246
  terminatorPos = i;
248
247
  i++;
249
248
  }
250
249
  if (!terminator) i++;
251
250
  }
252
- if (terminatorPos > pos) {
253
- const data = input.substring(pos, terminatorPos);
254
- yield emit({
255
- type: TOKEN_TYPES.DATA,
256
- pos,
257
- raw: data
258
- });
259
- }
251
+ if (terminatorPos > pos) yield emit({
252
+ type: TOKEN_TYPES.DATA,
253
+ pos,
254
+ raw: input.substring(pos, terminatorPos)
255
+ });
260
256
  if (terminator && terminator !== ABANDONED) yield emit({
261
257
  type: TOKEN_TYPES.FINAL,
262
258
  pos: terminatorPos,
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, CODE_TYPES, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, TOKEN_TYPES, parse, parser, tokenize, tokenizer } from "./parse-DBLatt5c.js";
1
+ import { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, CODE_TYPES, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, TOKEN_TYPES, parse, parser, tokenize, tokenizer } from "./parse-BCjxFvJh.js";
2
2
 
3
3
  export { APC, APC_CODE, APC_OPEN, BACKSLASH, BACKSLASH_CODE, BELL, BELL_CODE, C0_INTERRUPTERS, CAN, CAN_CODE, CODE_TYPES, CSI, CSI_CODE, CSI_OPEN, CSI_OPEN_CODE, DCS, DCS_CODE, DCS_OPEN, DEC_OPEN, ESC, ESC_CODE, INTERRUPTERS, OSC, OSC_CODE, OSC_OPEN, OSC_OPEN_CODE, PARAM_SEPARATOR, PM, PM_CODE, PM_OPEN, PRIVATE_OPENERS, SOS, SOS_CODE, SOS_OPEN, ST, STRING_OPENERS, ST_CODE, SUB, SUB_CODE, TOKEN_TYPES, parse, parser, tokenize, tokenizer };
@@ -74,6 +74,20 @@ const CODE_TYPES = {
74
74
  TEXT: "TEXT"
75
75
  };
76
76
 
77
+ //#endregion
78
+ //#region src/parsers/apc.ts
79
+ function parseAPC(introducer, dataTokens, final) {
80
+ const data = dataTokens.map((t) => t.raw).join("");
81
+ const raw = introducer.raw + data + (final?.raw || "");
82
+ return {
83
+ type: CODE_TYPES.STRING,
84
+ pos: introducer.pos,
85
+ raw,
86
+ command: "APC",
87
+ params: data ? [data] : []
88
+ };
89
+ }
90
+
77
91
  //#endregion
78
92
  //#region src/parsers/csi.ts
79
93
  function parseCSI(introducer, dataTokens, final) {
@@ -232,20 +246,6 @@ function parseOSC(introducer, dataTokens, final) {
232
246
  };
233
247
  }
234
248
 
235
- //#endregion
236
- //#region src/parsers/apc.ts
237
- function parseAPC(introducer, dataTokens, final) {
238
- const data = dataTokens.map((t) => t.raw).join("");
239
- const raw = introducer.raw + data + (final?.raw || "");
240
- return {
241
- type: CODE_TYPES.STRING,
242
- pos: introducer.pos,
243
- raw,
244
- command: "APC",
245
- params: data ? [data] : []
246
- };
247
- }
248
-
249
249
  //#endregion
250
250
  //#region src/parsers/pm.ts
251
251
  function parsePM(introducer, dataTokens, final) {
@@ -368,9 +368,8 @@ function* tokenizer(input) {
368
368
  }
369
369
  } else if (state === "SEQUENCE") {
370
370
  const pos = i;
371
- const code = currentCode;
372
371
  let data = "";
373
- if (code === CSI) while (i < input.length) {
372
+ if (currentCode === CSI) while (i < input.length) {
374
373
  const charCode = input.charCodeAt(i);
375
374
  const char = input[i];
376
375
  if (INTERRUPTERS.has(charCode)) {
@@ -401,10 +400,9 @@ function* tokenizer(input) {
401
400
  data += char;
402
401
  i++;
403
402
  }
404
- else if (code === ESC) {
403
+ else if (currentCode === ESC) {
405
404
  if (i < input.length) {
406
405
  const charCode = input.charCodeAt(i);
407
- const char = input[i];
408
406
  if (INTERRUPTERS.has(charCode)) {
409
407
  setState("GROUND");
410
408
  if (C0_INTERRUPTERS.has(charCode)) i++;
@@ -412,19 +410,19 @@ function* tokenizer(input) {
412
410
  yield emit$1({
413
411
  type: TOKEN_TYPES.FINAL,
414
412
  pos: i,
415
- raw: char
413
+ raw: input[i]
416
414
  });
417
415
  i++;
418
416
  setState("GROUND");
419
417
  }
420
418
  }
421
- } else if (code) while (i < input.length) {
419
+ } else if (currentCode) while (i < input.length) {
422
420
  const char = input[i];
423
421
  const charCode = char.charCodeAt(0);
424
422
  let terminator;
425
423
  if (charCode === ESC && input.charCodeAt(i + 1) === BACKSLASH) terminator = ESC_CODE + BACKSLASH_CODE;
426
424
  else if (charCode === ST) terminator = ST_CODE;
427
- else if (charCode === BELL && code === OSC) terminator = BELL_CODE;
425
+ else if (charCode === BELL && currentCode === OSC) terminator = BELL_CODE;
428
426
  if (terminator) {
429
427
  if (data) yield emit$1({
430
428
  type: TOKEN_TYPES.DATA,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansi-tools/parser",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Tokenize and parse strings containing ANSI escape sequences and control codes",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -45,8 +45,8 @@
45
45
  "directory": "packages/parser"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^24.6.1",
49
- "tsdown": "^0.15.6",
48
+ "@types/node": "^24.7.2",
49
+ "tsdown": "^0.15.7",
50
50
  "typescript": "^5.9.3"
51
51
  }
52
52
  }