@clerc/advanced-types 1.0.3 → 1.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.
@@ -6,30 +6,35 @@ declare class FlagValidationError extends Error {}
6
6
  //#region src/index.d.ts
7
7
  /**
8
8
  * Creates a Enum type function that validates the input against allowed values.
9
- * The display name will be formatted as "value1 | value2 | ..." for help output.
10
- *
11
- * @param values - Array of allowed string values
12
- * @returns A TypeFunction that validates and returns the input value
13
- * @throws {Error} If the value is not in the allowed values list
9
+ * The display name will be formatted as "value1 | value2 | ..." for help
10
+ * output.
14
11
  *
15
12
  * @example
13
+ *
16
14
  * ```typescript
17
- * const format = Enum(['json', 'yaml', 'xml']);
15
+ * const format = Enum(["json", "yaml", "xml"]);
18
16
  * // Help output will show: json | yaml | xml
19
17
  * ```
18
+ *
19
+ * @param values - Array of allowed string values
20
+ * @returns A TypeFunction that validates and returns the input value
21
+ * @throws {Error} If the value is not in the allowed values list
20
22
  */
21
23
  declare function Enum<T extends string>(...values: T[]): TypeFunction<T>;
22
24
  /**
23
- * Creates a range type function that validates the input is a number within the specified range.
25
+ * Creates a range type function that validates the input is a number within the
26
+ * specified range.
24
27
  *
25
28
  * @param min - The minimum acceptable value (inclusive)
26
29
  * @param max - The maximum acceptable value (inclusive)
27
30
  * @returns A TypeFunction that validates the input value
28
- * @throws {Error} If the value is not a number or is outside the specified range
31
+ * @throws {Error} If the value is not a number or is outside the specified
32
+ * range
29
33
  */
30
34
  declare function Range(min: number, max: number): TypeFunction<number>;
31
35
  /**
32
- * Creates a regex type function that validates the input against the provided pattern.
36
+ * Creates a regex type function that validates the input against the provided
37
+ * pattern.
33
38
  *
34
39
  * @param pattern - The regular expression pattern to validate against
35
40
  * @param description - Optional description for display purposes
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var e=class extends Error{};function t(...t){let n=(n=>{if(!t.includes(n))throw new e(`Invalid value: ${n}. Must be one of: ${t.join(`, `)}`);return n});return n.display=t.join(` | `),n}function n(t,n){let r=(r=>{let i=Number(r);if(Number.isNaN(i)||i<t||i>n)throw new e(`Invalid value: ${r}. Must be a number between ${t} and ${n}`);return i});return r.display=`${t} - ${n}`,r}function r(t,n){let r=(n=>{if(!t.test(n))throw new e(`Invalid value: ${n}. Must match pattern: ${t}`);return n});return r.display=n??`Regex: ${t.toString()}`,r}export{t as Enum,e as FlagValidationError,n as Range,r as Regex};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/advanced-types",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc advanced types",
@@ -23,19 +23,12 @@
23
23
  "license": "MIT",
24
24
  "sideEffects": false,
25
25
  "exports": {
26
- ".": "./dist/index.js"
27
- },
28
- "main": "./dist/index.js",
29
- "module": "./dist/index.js",
30
- "types": "dist/index.d.ts",
31
- "typesVersions": {
32
- "*": {
33
- "*": [
34
- "./dist/*",
35
- "./dist/index.d.ts"
36
- ]
37
- }
26
+ ".": "./dist/index.mjs",
27
+ "./package.json": "./package.json"
38
28
  },
29
+ "main": "./dist/index.mjs",
30
+ "module": "./dist/index.mjs",
31
+ "types": "./dist/index.d.mts",
39
32
  "files": [
40
33
  "dist"
41
34
  ],
@@ -43,7 +36,7 @@
43
36
  "access": "public"
44
37
  },
45
38
  "devDependencies": {
46
- "@clerc/parser": "1.0.3"
39
+ "@clerc/parser": "1.1.1"
47
40
  },
48
41
  "peerDependencies": {
49
42
  "@clerc/parser": "*"
package/dist/index.js DELETED
@@ -1,63 +0,0 @@
1
- //#region src/errors.ts
2
- var FlagValidationError = class extends Error {};
3
-
4
- //#endregion
5
- //#region src/index.ts
6
- /**
7
- * Creates a Enum type function that validates the input against allowed values.
8
- * The display name will be formatted as "value1 | value2 | ..." for help output.
9
- *
10
- * @param values - Array of allowed string values
11
- * @returns A TypeFunction that validates and returns the input value
12
- * @throws {Error} If the value is not in the allowed values list
13
- *
14
- * @example
15
- * ```typescript
16
- * const format = Enum(['json', 'yaml', 'xml']);
17
- * // Help output will show: json | yaml | xml
18
- * ```
19
- */
20
- function Enum(...values) {
21
- const fn = ((value) => {
22
- if (!values.includes(value)) throw new FlagValidationError(`Invalid value: ${value}. Must be one of: ${values.join(", ")}`);
23
- return value;
24
- });
25
- fn.display = values.join(" | ");
26
- return fn;
27
- }
28
- /**
29
- * Creates a range type function that validates the input is a number within the specified range.
30
- *
31
- * @param min - The minimum acceptable value (inclusive)
32
- * @param max - The maximum acceptable value (inclusive)
33
- * @returns A TypeFunction that validates the input value
34
- * @throws {Error} If the value is not a number or is outside the specified range
35
- */
36
- function Range(min, max) {
37
- const fn = ((value) => {
38
- const num = Number(value);
39
- if (Number.isNaN(num) || num < min || num > max) throw new FlagValidationError(`Invalid value: ${value}. Must be a number between ${min} and ${max}`);
40
- return num;
41
- });
42
- fn.display = `${min} - ${max}`;
43
- return fn;
44
- }
45
- /**
46
- * Creates a regex type function that validates the input against the provided pattern.
47
- *
48
- * @param pattern - The regular expression pattern to validate against
49
- * @param description - Optional description for display purposes
50
- * @returns A TypeFunction that validates the input value
51
- * @throws {Error} If the value does not match the regex pattern
52
- */
53
- function Regex(pattern, description) {
54
- const fn = ((value) => {
55
- if (!pattern.test(value)) throw new FlagValidationError(`Invalid value: ${value}. Must match pattern: ${pattern}`);
56
- return value;
57
- });
58
- fn.display = description ?? `Regex: ${pattern.toString()}`;
59
- return fn;
60
- }
61
-
62
- //#endregion
63
- export { Enum, FlagValidationError, Range, Regex };