@vnejs/helpers.tokenize-text 0.1.2 → 0.1.3
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/package.json +9 -10
- package/src/index.ts +40 -0
- package/tsconfig.json +17 -0
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/helpers.tokenize-text",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"src",
|
|
10
|
+
"tsconfig.json"
|
|
9
11
|
],
|
|
10
12
|
"scripts": {
|
|
11
13
|
"test": "npm run build && node tests.js",
|
|
12
|
-
"build": "
|
|
14
|
+
"build": "npx @vnejs/monorepo package",
|
|
13
15
|
"publish:major:plugin": "npm run publish:major",
|
|
14
16
|
"publish:minor:plugin": "npm run publish:minor",
|
|
15
17
|
"publish:patch:plugin": "npm run publish:patch",
|
|
16
|
-
"publish:major": "
|
|
17
|
-
"publish:minor": "
|
|
18
|
-
"publish:patch": "
|
|
18
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
19
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
20
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
19
21
|
},
|
|
20
22
|
"author": "",
|
|
21
|
-
"license": "ISC"
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"typescript": "^6.0.3"
|
|
24
|
-
}
|
|
23
|
+
"license": "ISC"
|
|
25
24
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const TOKEN_MARK_START_CHARS = ["{"] as const;
|
|
2
|
+
const TOKEN_MARK_END_CHARS: Record<string, string> = { "{": "}" };
|
|
3
|
+
|
|
4
|
+
export type TokenizedChar = {
|
|
5
|
+
token: string;
|
|
6
|
+
marks: string[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type TokenizeTextAcc = {
|
|
10
|
+
array: TokenizedChar[];
|
|
11
|
+
marks: string[];
|
|
12
|
+
isInsideMark?: boolean;
|
|
13
|
+
markEndChar?: string;
|
|
14
|
+
currentMark?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const reduceTokenize = (acc: TokenizeTextAcc, char: string): TokenizeTextAcc => {
|
|
18
|
+
if (acc.isInsideMark) {
|
|
19
|
+
const mark = acc.currentMark ?? "";
|
|
20
|
+
|
|
21
|
+
if (char !== acc.markEndChar) {
|
|
22
|
+
acc.currentMark = mark + char;
|
|
23
|
+
} else {
|
|
24
|
+
if (!mark.startsWith("/")) acc.marks.push(mark);
|
|
25
|
+
else acc.marks = acc.marks.filter((m) => m !== mark.slice(1));
|
|
26
|
+
|
|
27
|
+
acc.isInsideMark = false;
|
|
28
|
+
}
|
|
29
|
+
} else if ((TOKEN_MARK_START_CHARS as readonly string[]).includes(char)) {
|
|
30
|
+
acc.currentMark = "";
|
|
31
|
+
acc.isInsideMark = true;
|
|
32
|
+
acc.markEndChar = TOKEN_MARK_END_CHARS[char] || char;
|
|
33
|
+
} else {
|
|
34
|
+
acc.array.push({ token: char, marks: acc.marks.slice() });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return acc;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const tokenizeText = (str: string): TokenizedChar[] => [...str].reduce(reduceTokenize, { array: [], marks: [] }).array;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"noEmitOnError": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"rootDir": "src",
|
|
13
|
+
"outDir": "dist"
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts"],
|
|
16
|
+
"exclude": ["dist", "node_modules"]
|
|
17
|
+
}
|