shelving 1.185.1 → 1.185.2
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
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOption
|
|
|
20
20
|
}
|
|
21
21
|
/** Choose from an allowed set of values. */
|
|
22
22
|
export declare class ChoiceSchema<K extends string> extends Schema<K> implements Iterable<ChoiceOption<K>> {
|
|
23
|
-
readonly value: K;
|
|
23
|
+
readonly value: K | undefined;
|
|
24
24
|
readonly options: ChoiceOptions<K>;
|
|
25
25
|
constructor({ one, title, placeholder, options, value, ...rest }: ChoiceSchemaOptions<K>);
|
|
26
26
|
validate(unsafeValue?: unknown): K;
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray
|
|
1
|
+
import { isArray } from "../util/array.js";
|
|
2
2
|
import { getKeys, getProps, isProp } from "../util/object.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Get the options for a choice field as an array. */
|
|
@@ -19,14 +19,14 @@ export function isOption(options, option) {
|
|
|
19
19
|
/** Choose from an allowed set of values. */
|
|
20
20
|
export class ChoiceSchema extends Schema {
|
|
21
21
|
options;
|
|
22
|
-
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value
|
|
22
|
+
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value, ...rest }) {
|
|
23
23
|
super({ one, title, value, placeholder, ...rest });
|
|
24
24
|
this.options = options;
|
|
25
25
|
}
|
|
26
26
|
validate(unsafeValue = this.value) {
|
|
27
27
|
if (typeof unsafeValue === "string" && isOption(this.options, unsafeValue))
|
|
28
28
|
return unsafeValue;
|
|
29
|
-
throw "Unknown value";
|
|
29
|
+
throw unsafeValue ? "Unknown value" : "Required";
|
|
30
30
|
}
|
|
31
31
|
// Implement iterable.
|
|
32
32
|
*[Symbol.iterator]() {
|