@vnejs/helpers.tokenize-text 0.1.1 → 0.1.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/dist/index.d.ts +5 -0
- package/dist/index.js +27 -0
- package/package.json +15 -7
- package/index.js +0 -25
- package/tests.js +0 -7
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const TOKEN_MARK_START_CHARS = ["{"];
|
|
2
|
+
const TOKEN_MARK_END_CHARS = { "{": "}" };
|
|
3
|
+
const reduceTokenize = (acc, char) => {
|
|
4
|
+
if (acc.isInsideMark) {
|
|
5
|
+
const mark = acc.currentMark ?? "";
|
|
6
|
+
if (char !== acc.markEndChar) {
|
|
7
|
+
acc.currentMark = mark + char;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
if (!mark.startsWith("/"))
|
|
11
|
+
acc.marks.push(mark);
|
|
12
|
+
else
|
|
13
|
+
acc.marks = acc.marks.filter((m) => m !== mark.slice(1));
|
|
14
|
+
acc.isInsideMark = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (TOKEN_MARK_START_CHARS.includes(char)) {
|
|
18
|
+
acc.currentMark = "";
|
|
19
|
+
acc.isInsideMark = true;
|
|
20
|
+
acc.markEndChar = TOKEN_MARK_END_CHARS[char] || char;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
acc.array.push({ token: char, marks: acc.marks.slice() });
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
};
|
|
27
|
+
export const tokenizeText = (str) => [...str].reduce(reduceTokenize, { array: [], marks: [] }).array;
|
package/package.json
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/helpers.tokenize-text",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
|
-
"test": "
|
|
11
|
+
"test": "npm run build && node tests.js",
|
|
12
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
8
13
|
"publish:major:plugin": "npm run publish:major",
|
|
9
14
|
"publish:minor:plugin": "npm run publish:minor",
|
|
10
15
|
"publish:patch:plugin": "npm run publish:patch",
|
|
11
|
-
"publish:major": "npm version major && npm publish --access public",
|
|
12
|
-
"publish:minor": "npm version minor && npm publish --access public",
|
|
13
|
-
"publish:patch": "npm version patch && npm publish --access public"
|
|
16
|
+
"publish:major": "npm run build && npm version major && npm publish --access public",
|
|
17
|
+
"publish:minor": "npm run build && npm version minor && npm publish --access public",
|
|
18
|
+
"publish:patch": "npm run build && npm version patch && npm publish --access public"
|
|
14
19
|
},
|
|
15
20
|
"author": "",
|
|
16
|
-
"license": "ISC"
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^6.0.3"
|
|
24
|
+
}
|
|
17
25
|
}
|
package/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const TOKEN_MARK_START_CHARS = ["{"];
|
|
2
|
-
const TOKEN_MARK_END_CHARS = { "{": "}" };
|
|
3
|
-
|
|
4
|
-
const reduceTokenize = (acc, char) => {
|
|
5
|
-
if (acc.isInsideMark) {
|
|
6
|
-
if (char !== acc.markEndChar) {
|
|
7
|
-
acc.currentMark += char;
|
|
8
|
-
} else {
|
|
9
|
-
if (!acc.currentMark.startsWith("/")) acc.marks.push(acc.currentMark);
|
|
10
|
-
else acc.marks = acc.marks.filter((m) => m !== acc.currentMark.slice(1));
|
|
11
|
-
|
|
12
|
-
acc.isInsideMark = false;
|
|
13
|
-
}
|
|
14
|
-
} else if (TOKEN_MARK_START_CHARS.includes(char)) {
|
|
15
|
-
acc.currentMark = "";
|
|
16
|
-
acc.isInsideMark = true;
|
|
17
|
-
acc.markEndChar = TOKEN_MARK_END_CHARS[char] || char;
|
|
18
|
-
} else {
|
|
19
|
-
acc.array.push({ token: char, marks: acc.marks.slice() });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return acc;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const tokenizeText = (str) => [...str].reduce(reduceTokenize, { array: [], marks: [] }).array;
|
package/tests.js
DELETED