@vnejs/helpers.tokenize-text 0.1.1
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/index.js +25 -0
- package/package.json +17 -0
- package/tests.js +7 -0
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/helpers.tokenize-text",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"publish:major:plugin": "npm run publish:major",
|
|
9
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
10
|
+
"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"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC"
|
|
17
|
+
}
|
package/tests.js
ADDED