@clerc/parser 1.0.0-beta.27 → 1.0.0-beta.29

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  # @clerc/parser
2
2
 
3
+ [![NPM version](https://img.shields.io/npm/v/@clerc/parser?color=a1b858&label=)](https://www.npmjs.com/package/@clerc/parser)
4
+
3
5
  A powerful, lightweight, and flexible command-line arguments parser.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
- npm install @clerc/parser
9
- # or
10
- yarn add @clerc/parser
11
- # or
12
- pnpm add @clerc/parser
10
+ $ npm install @clerc/parser
11
+ $ yarn add @clerc/parser
12
+ $ pnpm add @clerc/parser
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -360,3 +360,7 @@ BENCH Summary
360
360
  3.85x faster than nopt
361
361
  27.11x faster than yargs-parser
362
362
  ```
363
+
364
+ ## 📝 License
365
+
366
+ [MIT](../../LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
package/dist/index.d.ts CHANGED
@@ -8,11 +8,6 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
8
8
  type IsAny<T> = 0 extends 1 & T ? true : false;
9
9
  type RequireExactlyOneOrNone<T, Keys extends keyof T = keyof T> = ({ [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, never>> }[Keys] & Omit<T, Keys>) | (Partial<Record<Keys, never>> & Omit<T, Keys>);
10
10
  //#endregion
11
- //#region src/iterator.d.ts
12
- declare const KNOWN_FLAG = "known-flag";
13
- declare const UNKNOWN_FLAG = "unknown-flag";
14
- declare const PARAMETER = "parameter";
15
- //#endregion
16
11
  //#region src/types.d.ts
17
12
  interface FlagDefaultValueFunction<T> {
18
13
  (): T;
@@ -146,40 +141,10 @@ type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]>
146
141
  */
147
142
  type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
148
143
  //#endregion
149
- //#region src/flag-types.d.ts
150
- /**
151
- * Creates a Enum type function that validates the input against allowed values.
152
- * The display name will be formatted as "value1 | value2 | ..." for help output.
153
- *
154
- * @param values - Array of allowed string values
155
- * @returns A TypeFunction that validates and returns the input value
156
- * @throws {Error} If the value is not in the allowed values list
157
- *
158
- * @example
159
- * ```typescript
160
- * const format = Enum(['json', 'yaml', 'xml']);
161
- * // Help output will show: json | yaml | xml
162
- * ```
163
- */
164
- declare function Enum<T extends string>(...values: T[]): TypeFunction<T>;
165
- /**
166
- * Creates a range type function that validates the input is a number within the specified range.
167
- *
168
- * @param min - The minimum acceptable value (inclusive)
169
- * @param max - The maximum acceptable value (inclusive)
170
- * @returns A TypeFunction that validates the input value
171
- * @throws {Error} If the value is not a number or is outside the specified range
172
- */
173
- declare function Range(min: number, max: number): TypeFunction<number>;
174
- /**
175
- * Creates a regex type function that validates the input against the provided pattern.
176
- *
177
- * @param pattern - The regular expression pattern to validate against
178
- * @param description - Optional description for display purposes
179
- * @returns A TypeFunction that validates the input value
180
- * @throws {Error} If the value does not match the regex pattern
181
- */
182
- declare function Regex(pattern: RegExp, description?: string): TypeFunction<string>;
144
+ //#region src/iterator.d.ts
145
+ declare const KNOWN_FLAG = "known-flag";
146
+ declare const UNKNOWN_FLAG = "unknown-flag";
147
+ declare const PARAMETER = "parameter";
183
148
  //#endregion
184
149
  //#region src/parse.d.ts
185
150
  declare const DOUBLE_DASH = "--";
@@ -189,4 +154,4 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
189
154
  };
190
155
  declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
191
156
  //#endregion
192
- export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, Range, RawInputType, Regex, TypeFunction, TypeValue, UNKNOWN_FLAG, createParser, parse };
157
+ export { BaseFlagOptions, DOUBLE_DASH, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, TypeFunction, TypeValue, UNKNOWN_FLAG, createParser, parse };
package/dist/index.js CHANGED
@@ -6,64 +6,6 @@ var InvalidSchemaError = class extends Error {
6
6
  }
7
7
  };
8
8
 
9
- //#endregion
10
- //#region src/flag-types.ts
11
- /**
12
- * Creates a Enum type function that validates the input against allowed values.
13
- * The display name will be formatted as "value1 | value2 | ..." for help output.
14
- *
15
- * @param values - Array of allowed string values
16
- * @returns A TypeFunction that validates and returns the input value
17
- * @throws {Error} If the value is not in the allowed values list
18
- *
19
- * @example
20
- * ```typescript
21
- * const format = Enum(['json', 'yaml', 'xml']);
22
- * // Help output will show: json | yaml | xml
23
- * ```
24
- */
25
- function Enum(...values) {
26
- const fn = ((value) => {
27
- if (!values.includes(value)) throw new Error(`Invalid value: ${value}. Must be one of: ${values.join(", ")}`);
28
- return value;
29
- });
30
- fn.display = values.join(" | ");
31
- return fn;
32
- }
33
- /**
34
- * Creates a range type function that validates the input is a number within the specified range.
35
- *
36
- * @param min - The minimum acceptable value (inclusive)
37
- * @param max - The maximum acceptable value (inclusive)
38
- * @returns A TypeFunction that validates the input value
39
- * @throws {Error} If the value is not a number or is outside the specified range
40
- */
41
- function Range(min, max) {
42
- const fn = ((value) => {
43
- const num = Number(value);
44
- if (Number.isNaN(num) || num < min || num > max) throw new Error(`Invalid value: ${value}. Must be a number between ${min} and ${max}`);
45
- return num;
46
- });
47
- fn.display = `${min} - ${max}`;
48
- return fn;
49
- }
50
- /**
51
- * Creates a regex type function that validates the input against the provided pattern.
52
- *
53
- * @param pattern - The regular expression pattern to validate against
54
- * @param description - Optional description for display purposes
55
- * @returns A TypeFunction that validates the input value
56
- * @throws {Error} If the value does not match the regex pattern
57
- */
58
- function Regex(pattern, description) {
59
- const fn = ((value) => {
60
- if (!pattern.test(value)) throw new Error(`Invalid value: ${value}. Must match pattern: ${pattern}`);
61
- return value;
62
- });
63
- fn.display = description ?? `Regex: ${pattern.toString()}`;
64
- return fn;
65
- }
66
-
67
9
  //#endregion
68
10
  //#region src/iterator.ts
69
11
  const KNOWN_FLAG = "known-flag";
@@ -380,4 +322,4 @@ function createParser(options = {}) {
380
322
  const parse = (args, options = {}) => createParser(options).parse(args);
381
323
 
382
324
  //#endregion
383
- export { DOUBLE_DASH, Enum, InvalidSchemaError, KNOWN_FLAG, PARAMETER, Range, Regex, UNKNOWN_FLAG, createParser, parse };
325
+ export { DOUBLE_DASH, InvalidSchemaError, KNOWN_FLAG, PARAMETER, UNKNOWN_FLAG, createParser, parse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/parser",
3
- "version": "1.0.0-beta.27",
3
+ "version": "1.0.0-beta.29",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc parser",
@@ -56,6 +56,6 @@
56
56
  "nopt": "^9.0.0",
57
57
  "type-flag": "^4.0.3",
58
58
  "yargs-parser": "^22.0.0",
59
- "@clerc/utils": "1.0.0-beta.27"
59
+ "@clerc/utils": "1.0.0-beta.29"
60
60
  }
61
61
  }