@typescriptprime/parsing 1.0.4 → 1.1.0-build.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/README.md +2 -5
- package/dist/index.js +3 -53
- package/dist/index.js.map +1 -7
- package/dist/postprocessing/index.js +32 -0
- package/dist/postprocessing/index.js.map +1 -0
- package/dist/preprocessing/index.js +15 -0
- package/dist/preprocessing/index.js.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -9
- package/dist/types/index.d.ts +0 -3
- package/dist/types/postprocessing/index.d.ts +0 -13
- package/dist/types/preprocessing/index.d.ts +0 -11
- package/dist/types/types.d.ts +0 -9
package/README.md
CHANGED
|
@@ -100,14 +100,11 @@ const { Options } = await PostProcessing(Tokens)
|
|
|
100
100
|
|
|
101
101
|
## Scripts
|
|
102
102
|
|
|
103
|
-
- `npm run build` — runs: `
|
|
103
|
+
- `npm run build` — runs: `tsc -p sources/tsconfig.json` to bundle the compiled JS and emit declarations.
|
|
104
104
|
- `npm test` — runs AVA tests.
|
|
105
105
|
- `npm run lint` — runs ESLint checks.
|
|
106
106
|
|
|
107
|
-
This project is published as an ES module.
|
|
108
|
-
|
|
109
|
-
- `npm run build:esbuild` — bundle with esbuild (JS output)
|
|
110
|
-
- `npm run build:tsc` — emit TypeScript declarations only
|
|
107
|
+
This project is published as an ES module.
|
|
111
108
|
|
|
112
109
|
The package `exports` are configured in `package.json` so importing the default entry works with ESM loaders.
|
|
113
110
|
|
package/dist/index.js
CHANGED
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// node_modules/es-toolkit/dist/string/words.mjs
|
|
7
|
-
var CASE_SPLIT_PATTERN = /\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;
|
|
8
|
-
function words(str) {
|
|
9
|
-
return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// node_modules/es-toolkit/dist/string/pascalCase.mjs
|
|
13
|
-
function pascalCase(str) {
|
|
14
|
-
const words$1 = words(str);
|
|
15
|
-
return words$1.map((word) => capitalize(word)).join("");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// sources/postprocessing/index.ts
|
|
19
|
-
async function PostProcessing(Args, FuncOptions = {
|
|
20
|
-
NamingConvention: pascalCase
|
|
21
|
-
}) {
|
|
22
|
-
const Options = /* @__PURE__ */ Object.create(null);
|
|
23
|
-
const Positional = [];
|
|
24
|
-
for (let I = 0; I < Args.length; I++) {
|
|
25
|
-
if (Args[I] === "--") {
|
|
26
|
-
Positional.push(...Args.slice(I + 1));
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
if (Args[I].startsWith("--")) {
|
|
30
|
-
if (I + 1 === Args.length || Args[I + 1].startsWith("--")) {
|
|
31
|
-
Options[await FuncOptions.NamingConvention(Args[I])] = true;
|
|
32
|
-
} else {
|
|
33
|
-
Options[await FuncOptions.NamingConvention(Args[I])] = Args[I + 1];
|
|
34
|
-
I++;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { Options, Positional };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// sources/preprocessing/index.ts
|
|
42
|
-
function PreProcessing(Args) {
|
|
43
|
-
if (Args[2].startsWith("--")) {
|
|
44
|
-
return Args.slice(2);
|
|
45
|
-
} else {
|
|
46
|
-
return Args.slice(1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
PostProcessing,
|
|
51
|
-
PreProcessing
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { PostProcessing } from './postprocessing/index.js';
|
|
2
|
+
export { PreProcessing } from './preprocessing/index.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../node_modules/es-toolkit/dist/string/capitalize.mjs", "../node_modules/es-toolkit/dist/string/words.mjs", "../node_modules/es-toolkit/dist/string/pascalCase.mjs", "../sources/postprocessing/index.ts", "../sources/preprocessing/index.ts"],
|
|
4
|
-
"sourcesContent": ["function capitalize(str) {\n return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase());\n}\n\nexport { capitalize };\n", "const CASE_SPLIT_PATTERN = /\\p{Lu}?\\p{Ll}+|[0-9]+|\\p{Lu}+(?!\\p{Ll})|\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{L}+/gu;\nfunction words(str) {\n return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);\n}\n\nexport { CASE_SPLIT_PATTERN, words };\n", "import { capitalize } from './capitalize.mjs';\nimport { words } from './words.mjs';\n\nfunction pascalCase(str) {\n const words$1 = words(str);\n return words$1.map(word => capitalize(word)).join('');\n}\n\nexport { pascalCase };\n", "import * as ESToolkit from 'es-toolkit'\nimport type { JSONValue, IParsingOptions } from '../types.js'\n\n/**\n * Parses a list of CLI-style arguments into a structured options object and positional arguments.\n *\n * @typeParam I - The shape of the options object produced from the parsed arguments.\n * @param Args - The raw argument tokens, including option flags and positional values.\n * @param FuncOptions - Configuration for post-processing behavior, such as the naming convention transformer.\n * @returns A promise resolving to an object containing the parsed options and remaining positional arguments.\n */\nexport async function PostProcessing<I extends JSONValue>(Args: string[], FuncOptions: IParsingOptions = {\n NamingConvention: ESToolkit.pascalCase\n}): Promise<{ Options: I, Positional: string[] }> {\n const Options: Record<string, boolean | string> = Object.create(null)\n const Positional: string[] = []\n\n for (let I = 0; I < Args.length; I++) {\n if (Args[I] === '--') {\n Positional.push(...Args.slice(I + 1))\n break\n }\n\n if (Args[I].startsWith('--')) {\n if (I + 1 === Args.length || Args[I + 1].startsWith('--')) {\n Options[await FuncOptions.NamingConvention(Args[I])] = true\n } else {\n Options[await FuncOptions.NamingConvention(Args[I])] = Args[I + 1]\n I++\n }\n }\n }\n\n return { Options: Options as I, Positional }\n}", "import type * as Process from 'node:process'\n\ntype DropFirstANDTwo<T extends readonly unknown[]> = T extends readonly [unknown, unknown, ...infer Tail] ? Tail : []\ntype DropFirst<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Tail] ? Tail : []\n\n/**\n * Returns a filtered `process.argv` with only options and their values.\n * \n * @param {string} Args - A value of `process.argv`.\n * @returns A filtered `process.argv` with only options and their values.\n */\nexport function PreProcessing<Args extends typeof Process.argv>(Args: Args): DropFirstANDTwo<Args> | DropFirst<Args> {\n if (Args[2].startsWith('--')) {\n return Args.slice(2) as DropFirstANDTwo<Args>\n } else {\n return Args.slice(1) as DropFirst<Args>\n }\n}"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,WAAW,KAAK;AACrB,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,EAAE,YAAY;AACnE;;;ACFA,IAAM,qBAAqB;AAC3B,SAAS,MAAM,KAAK;AAChB,SAAO,MAAM,KAAK,IAAI,MAAM,kBAAkB,KAAK,CAAC,CAAC;AACzD;;;ACAA,SAAS,WAAW,KAAK;AACrB,QAAM,UAAU,MAAM,GAAG;AACzB,SAAO,QAAQ,IAAI,UAAQ,WAAW,IAAI,CAAC,EAAE,KAAK,EAAE;AACxD;;;ACKA,eAAsB,eAAoC,MAAgB,cAA+B;AAAA,EACvG,kBAA4B;AAC9B,GAAkD;AAChD,QAAM,UAA4C,uBAAO,OAAO,IAAI;AACpE,QAAM,aAAuB,CAAC;AAE9B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,KAAK,CAAC,MAAM,MAAM;AACpB,iBAAW,KAAK,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC;AACpC;AAAA,IACF;AAEA,QAAI,KAAK,CAAC,EAAE,WAAW,IAAI,GAAG;AAC5B,UAAI,IAAI,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,EAAE,WAAW,IAAI,GAAG;AACzD,gBAAQ,MAAM,YAAY,iBAAiB,KAAK,CAAC,CAAC,CAAC,IAAI;AAAA,MACzD,OAAO;AACL,gBAAQ,MAAM,YAAY,iBAAiB,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,SAAuB,WAAW;AAC7C;;;ACvBO,SAAS,cAAgD,MAAqD;AACnH,MAAI,KAAK,CAAC,EAAE,WAAW,IAAI,GAAG;AAC5B,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB,OAAO;AACL,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../sources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as ESToolkit from 'es-toolkit';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a list of CLI-style arguments into a structured options object and positional arguments.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam I - The shape of the options object produced from the parsed arguments.
|
|
6
|
+
* @param Args - The raw argument tokens, including option flags and positional values.
|
|
7
|
+
* @param FuncOptions - Configuration for post-processing behavior, such as the naming convention transformer.
|
|
8
|
+
* @returns A promise resolving to an object containing the parsed options and remaining positional arguments.
|
|
9
|
+
*/
|
|
10
|
+
export async function PostProcessing(Args, FuncOptions = {
|
|
11
|
+
NamingConvention: ESToolkit.pascalCase
|
|
12
|
+
}) {
|
|
13
|
+
const Options = Object.create(null);
|
|
14
|
+
const Positional = [];
|
|
15
|
+
for (let I = 0; I < Args.length; I++) {
|
|
16
|
+
if (Args[I] === '--') {
|
|
17
|
+
Positional.push(...Args.slice(I + 1));
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (Args[I].startsWith('--')) {
|
|
21
|
+
if (I + 1 === Args.length || Args[I + 1].startsWith('--')) {
|
|
22
|
+
Options[await FuncOptions.NamingConvention(Args[I])] = true;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
Options[await FuncOptions.NamingConvention(Args[I])] = Args[I + 1];
|
|
26
|
+
I++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { Options: Options, Positional };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../sources/postprocessing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AAGvC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAsB,IAAc,EAAE,cAA+B;IACvG,gBAAgB,EAAE,SAAS,CAAC,UAAU;CACvC;IACC,MAAM,OAAO,GAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACrE,MAAM,UAAU,GAAa,EAAE,CAAA;IAE/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACrB,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACrC,MAAK;QACP,CAAC;QAED,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1D,OAAO,CAAC,MAAM,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;YAC7D,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;gBAClE,CAAC,EAAE,CAAA;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAY,EAAE,UAAU,EAAE,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a filtered `process.argv` with only options and their values.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} Args - A value of `process.argv`.
|
|
5
|
+
* @returns A filtered `process.argv` with only options and their values.
|
|
6
|
+
*/
|
|
7
|
+
export function PreProcessing(Args) {
|
|
8
|
+
if (Args[2].startsWith('--')) {
|
|
9
|
+
return Args.slice(2);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return Args.slice(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../sources/preprocessing/index.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAmC,IAAU;IACxE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAA0B,CAAA;IAC/C,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAoB,CAAA;IACzC,CAAC;AACH,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../sources/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescriptprime/parsing",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.1.0-build.1",
|
|
5
5
|
"description": "Lightweight helper utilities for parsing CLI-style arguments, implemented in TypeScript",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|
|
@@ -10,9 +10,7 @@
|
|
|
10
10
|
"ci"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build
|
|
14
|
-
"build:tsc": "tsc sources/index.ts --outDir dist/types --declaration --emitDeclarationOnly",
|
|
15
|
-
"build": "npm run build:esbuild && npm run build:tsc",
|
|
13
|
+
"build": "tsc -p sources/tsconfig.json",
|
|
16
14
|
"lint": "eslint . --ext .ts",
|
|
17
15
|
"test": "ava"
|
|
18
16
|
},
|
|
@@ -52,15 +50,14 @@
|
|
|
52
50
|
},
|
|
53
51
|
"devDependencies": {
|
|
54
52
|
"@ava/typescript": "^6.0.0",
|
|
55
|
-
"@types/node": "^24.10.
|
|
53
|
+
"@types/node": "^24.10.9",
|
|
56
54
|
"ava": "^6.4.1",
|
|
57
|
-
"
|
|
58
|
-
"eslint": "^9.39.1",
|
|
55
|
+
"eslint": "^9.39.2",
|
|
59
56
|
"tsx": "^4.21.0",
|
|
60
57
|
"typescript": "^5.9.3",
|
|
61
|
-
"typescript-eslint": "^8.
|
|
58
|
+
"typescript-eslint": "^8.54.0"
|
|
62
59
|
},
|
|
63
60
|
"dependencies": {
|
|
64
|
-
"es-toolkit": "^1.
|
|
61
|
+
"es-toolkit": "^1.44.0"
|
|
65
62
|
}
|
|
66
63
|
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { JSONValue, IParsingOptions } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Parses a list of CLI-style arguments into a structured options object and positional arguments.
|
|
4
|
-
*
|
|
5
|
-
* @typeParam I - The shape of the options object produced from the parsed arguments.
|
|
6
|
-
* @param Args - The raw argument tokens, including option flags and positional values.
|
|
7
|
-
* @param FuncOptions - Configuration for post-processing behavior, such as the naming convention transformer.
|
|
8
|
-
* @returns A promise resolving to an object containing the parsed options and remaining positional arguments.
|
|
9
|
-
*/
|
|
10
|
-
export declare function PostProcessing<I extends JSONValue>(Args: string[], FuncOptions?: IParsingOptions): Promise<{
|
|
11
|
-
Options: I;
|
|
12
|
-
Positional: string[];
|
|
13
|
-
}>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type * as Process from 'node:process';
|
|
2
|
-
type DropFirstANDTwo<T extends readonly unknown[]> = T extends readonly [unknown, unknown, ...infer Tail] ? Tail : [];
|
|
3
|
-
type DropFirst<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Tail] ? Tail : [];
|
|
4
|
-
/**
|
|
5
|
-
* Returns a filtered `process.argv` with only options and their values.
|
|
6
|
-
*
|
|
7
|
-
* @param {string} Args - A value of `process.argv`.
|
|
8
|
-
* @returns A filtered `process.argv` with only options and their values.
|
|
9
|
-
*/
|
|
10
|
-
export declare function PreProcessing<Args extends typeof Process.argv>(Args: Args): DropFirstANDTwo<Args> | DropFirst<Args>;
|
|
11
|
-
export {};
|
package/dist/types/types.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type JSONPrimitive = string | number | boolean | null;
|
|
2
|
-
export interface JSONObject {
|
|
3
|
-
[key: string]: JSONValue;
|
|
4
|
-
}
|
|
5
|
-
export type JSONArray = Array<JSONValue>;
|
|
6
|
-
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
7
|
-
export interface IParsingOptions {
|
|
8
|
-
NamingConvention?: ((PropertyName: string) => string) | ((PropertyName: string) => Promise<string>);
|
|
9
|
-
}
|