shelving 1.18.0 → 1.19.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.
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "./Schema.js";
|
|
2
|
+
/** Specify a specific list of allowed values. */
|
|
3
|
+
export declare type AllowedOptions<T extends string> = ReadonlyArray<T> | {
|
|
4
|
+
readonly [K in T]: string;
|
|
5
|
+
};
|
|
6
|
+
/** Validate a value against a specific set of allowed values. */
|
|
7
|
+
export declare function validateAllowed<T extends string>(unsafeString: string, allowed: AllowedOptions<T>): T;
|
|
8
|
+
/** Define a valid string from an allowed set of strings. */
|
|
9
|
+
export declare class AllowSchema<T extends string> extends Schema<T> {
|
|
10
|
+
readonly allow: AllowedOptions<T>;
|
|
11
|
+
readonly value: T | null;
|
|
12
|
+
constructor({ allow, value, ...options }: ConstructorParameters<typeof Schema>[0] & {
|
|
13
|
+
allow: AllowedOptions<T>;
|
|
14
|
+
value?: T | null;
|
|
15
|
+
});
|
|
16
|
+
validate(unsafeValue?: unknown): T;
|
|
17
|
+
}
|
|
18
|
+
/** Valid string from an allowed set of strings. */
|
|
19
|
+
export declare const ALLOW: <T extends string>(allow: AllowedOptions<T>) => AllowSchema<T>;
|
|
@@ -14,15 +14,15 @@ export function validateAllowed(unsafeString, allowed) {
|
|
|
14
14
|
throw new InvalidFeedback("Unknown value", { value: unsafeString });
|
|
15
15
|
}
|
|
16
16
|
/** Define a valid string from an allowed set of strings. */
|
|
17
|
-
export class
|
|
18
|
-
constructor({ allow, ...options }) {
|
|
17
|
+
export class AllowSchema extends Schema {
|
|
18
|
+
constructor({ allow, value = null, ...options }) {
|
|
19
19
|
super(options);
|
|
20
20
|
this.allow = allow;
|
|
21
|
+
this.value = value;
|
|
21
22
|
}
|
|
22
|
-
validate(unsafeValue) {
|
|
23
|
-
|
|
24
|
-
return validateAllowed(unsafeString, this.allow);
|
|
23
|
+
validate(unsafeValue = this.value) {
|
|
24
|
+
return validateAllowed(toString(unsafeValue), this.allow);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/** Valid string from an allowed set of strings. */
|
|
28
|
-
export const ALLOW = (allow) => new
|
|
28
|
+
export const ALLOW = (allow) => new AllowSchema({ allow: allow });
|
package/schema/index.d.ts
CHANGED
package/schema/index.js
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Schema } from "./Schema.js";
|
|
2
|
-
/** Specify a specific list of allowed values. */
|
|
3
|
-
export declare type Allowed<T extends string> = ReadonlyArray<T> | {
|
|
4
|
-
readonly [K in T]: string;
|
|
5
|
-
};
|
|
6
|
-
/** Validate a value against a specific set of allowed values. */
|
|
7
|
-
export declare function validateAllowed<T extends string>(unsafeString: string, allowed: Allowed<T>): T;
|
|
8
|
-
/** Define a valid string from an allowed set of strings. */
|
|
9
|
-
export declare class AllowedSchema<T extends string> extends Schema<T> {
|
|
10
|
-
readonly allow: Allowed<T>;
|
|
11
|
-
constructor({ allow, ...options }: ConstructorParameters<typeof Schema>[0] & {
|
|
12
|
-
allow: Allowed<T>;
|
|
13
|
-
});
|
|
14
|
-
validate(unsafeValue: unknown): T;
|
|
15
|
-
}
|
|
16
|
-
/** Valid string from an allowed set of strings. */
|
|
17
|
-
export declare const ALLOW: <T extends string>(allow: Allowed<T>) => AllowedSchema<T>;
|