@vnejs/helpers.tokenize-exec-line 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 CHANGED
@@ -1,25 +1,24 @@
1
1
  {
2
2
  "name": "@vnejs/helpers.tokenize-exec-line",
3
- "version": "0.1.2",
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": "rm -rf dist && tsc -p tsconfig.json",
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": "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"
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,49 @@
1
+ const NUMBER_REGEXP = /^-?\d+(\.\d+)?$/;
2
+
3
+ const TOKEN_INSIDE_START_CHARS = ["{", "(", "[", '"', "'", "`"] as const;
4
+ const TOKEN_INSIDE_END_CHARS: Record<string, string> = { "{": "}", "(": ")", "[": "]" };
5
+
6
+ type TokenizeExecLineAcc = {
7
+ array: string[];
8
+ isInsideToken?: boolean;
9
+ tokenEndChar?: string;
10
+ };
11
+
12
+ const fromStrToCorrectType = (token: string): string | number | boolean => {
13
+ if (token === "true") return true;
14
+ if (token === "false") return false;
15
+ if (NUMBER_REGEXP.test(token)) return token.includes(".") ? parseFloat(token) : parseInt(token, 10);
16
+ return token;
17
+ };
18
+
19
+ const toLength = (q: string) => q.length;
20
+
21
+ const reduceTokenize = (acc: TokenizeExecLineAcc, char: string): TokenizeExecLineAcc => {
22
+ if (acc.isInsideToken) {
23
+ if (char !== acc.tokenEndChar) acc.array[acc.array.length - 1] += char;
24
+ else {
25
+ acc.array.push("");
26
+ acc.isInsideToken = false;
27
+ }
28
+
29
+ return acc;
30
+ }
31
+
32
+ if ((TOKEN_INSIDE_START_CHARS as readonly string[]).includes(char)) {
33
+ acc.array.push("");
34
+ acc.isInsideToken = true;
35
+ acc.tokenEndChar = TOKEN_INSIDE_END_CHARS[char] || char;
36
+ return acc;
37
+ }
38
+
39
+ if (char === " ") acc.array.push("");
40
+ else acc.array[acc.array.length - 1] += char;
41
+
42
+ return acc;
43
+ };
44
+
45
+ export const tokenizeExecLine = (text: string): (string | number | boolean)[] =>
46
+ [...text]
47
+ .reduce(reduceTokenize, { array: [""] })
48
+ .array.filter(toLength)
49
+ .map(fromStrToCorrectType);
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
+ }