@clerc/advanced-types 1.0.3 → 1.1.0
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
|
|
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([
|
|
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
|
|
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
|
|
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
|
|
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
|
|
@@ -5,17 +5,19 @@ var FlagValidationError = class extends Error {};
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
/**
|
|
7
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
|
|
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
|
|
8
|
+
* The display name will be formatted as "value1 | value2 | ..." for help
|
|
9
|
+
* output.
|
|
13
10
|
*
|
|
14
11
|
* @example
|
|
12
|
+
*
|
|
15
13
|
* ```typescript
|
|
16
|
-
* const format = Enum([
|
|
14
|
+
* const format = Enum(["json", "yaml", "xml"]);
|
|
17
15
|
* // Help output will show: json | yaml | xml
|
|
18
16
|
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param values - Array of allowed string values
|
|
19
|
+
* @returns A TypeFunction that validates and returns the input value
|
|
20
|
+
* @throws {Error} If the value is not in the allowed values list
|
|
19
21
|
*/
|
|
20
22
|
function Enum(...values) {
|
|
21
23
|
const fn = ((value) => {
|
|
@@ -26,12 +28,14 @@ function Enum(...values) {
|
|
|
26
28
|
return fn;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
|
-
* Creates a range type function that validates the input is a number within the
|
|
31
|
+
* Creates a range type function that validates the input is a number within the
|
|
32
|
+
* specified range.
|
|
30
33
|
*
|
|
31
34
|
* @param min - The minimum acceptable value (inclusive)
|
|
32
35
|
* @param max - The maximum acceptable value (inclusive)
|
|
33
36
|
* @returns A TypeFunction that validates the input value
|
|
34
|
-
* @throws {Error} If the value is not a number or is outside the specified
|
|
37
|
+
* @throws {Error} If the value is not a number or is outside the specified
|
|
38
|
+
* range
|
|
35
39
|
*/
|
|
36
40
|
function Range(min, max) {
|
|
37
41
|
const fn = ((value) => {
|
|
@@ -43,7 +47,8 @@ function Range(min, max) {
|
|
|
43
47
|
return fn;
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
* Creates a regex type function that validates the input against the provided
|
|
50
|
+
* Creates a regex type function that validates the input against the provided
|
|
51
|
+
* pattern.
|
|
47
52
|
*
|
|
48
53
|
* @param pattern - The regular expression pattern to validate against
|
|
49
54
|
* @param description - Optional description for display purposes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/advanced-types",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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.
|
|
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
|
|
39
|
+
"@clerc/parser": "1.1.0"
|
|
47
40
|
},
|
|
48
41
|
"peerDependencies": {
|
|
49
42
|
"@clerc/parser": "*"
|