@ansi-tools/parser 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -20,6 +20,8 @@ Parser for ANSI escape sequences.
20
20
  - ✅ Zero dependencies
21
21
  - ✅ Separate optimized modules for raw and escaped input
22
22
 
23
+ Used by [ansi.tools](https://ansi.tools).
24
+
23
25
  ## Installation
24
26
 
25
27
  ```bash
@@ -145,10 +147,11 @@ for (const code of codes) {
145
147
  ## Type Definitions
146
148
 
147
149
  ```ts
148
- function parse(input: string): CODE[];
149
150
  function tokenize(input: string): TOKEN[];
150
- function* parser(tokens: Generator<TOKEN>): Generator<CODE>;
151
+ function parse(input: string): CODE[];
152
+
151
153
  function* tokenizer(input: string): Generator<TOKEN>;
154
+ function* parser(tokens: Generator<TOKEN>): Generator<CODE>;
152
155
  ```
153
156
 
154
157
  ### CODE
package/dist/escaped.js CHANGED
@@ -61,7 +61,9 @@ function* tokenizer(input) {
61
61
  if (i < input.length) {
62
62
  const candidates = INTRODUCER_LOOKUP.get(input[i + 1]);
63
63
  if (candidates) {
64
+ let matched = false;
64
65
  for (const [sequence, len] of candidates) if (i + len <= input.length && input.substring(i, i + len) === sequence) {
66
+ matched = true;
65
67
  if (sequence === CSI_ESCAPED) {
66
68
  yield emit({
67
69
  type: TOKEN_TYPES.INTRODUCER,
@@ -131,7 +133,8 @@ function* tokenizer(input) {
131
133
  }
132
134
  break;
133
135
  }
134
- }
136
+ if (!matched) i++;
137
+ } else i++;
135
138
  }
136
139
  } else if (state === "SEQUENCE") {
137
140
  let terminator = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansi-tools/parser",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Tokenize and parse strings containing ANSI escape sequences and control codes",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -19,6 +19,13 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
+ "scripts": {
23
+ "prebuild": "pnpm type-check && pnpm test",
24
+ "build": "tsdown --dts src/index.ts src/escaped.ts",
25
+ "test": "node --test",
26
+ "type-check": "tsc",
27
+ "prepack": "pnpm build"
28
+ },
22
29
  "keywords": [
23
30
  "ansi",
24
31
  "escape codes",
@@ -29,15 +36,16 @@
29
36
  "publishConfig": {
30
37
  "access": "public"
31
38
  },
39
+ "homepage": "https://github.com/webpro/ANSI.tools/tree/main/packages/parser",
40
+ "bugs": "https://github.com/webpro/ANSI.tools/issues",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "github:webpro/ANSI.tools",
44
+ "directory": "packages/parser"
45
+ },
32
46
  "devDependencies": {
33
47
  "@types/node": "^24.0.13",
34
48
  "tsdown": "^0.12.9",
35
49
  "typescript": "^5.8.3"
36
- },
37
- "scripts": {
38
- "prebuild": "pnpm type-check && pnpm test",
39
- "build": "tsdown --dts src/index.ts src/escaped.ts",
40
- "test": "node --test",
41
- "type-check": "tsc"
42
50
  }
43
- }
51
+ }