shelving 1.161.2 → 1.162.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.
package/package.json
CHANGED
|
@@ -3,11 +3,13 @@ import { Schema } from "./Schema.js";
|
|
|
3
3
|
/** Allowed options for `BooleanSchema` */
|
|
4
4
|
export interface BooleanSchemaOptions extends SchemaOptions {
|
|
5
5
|
readonly value?: boolean | undefined;
|
|
6
|
+
readonly required?: boolean | undefined;
|
|
6
7
|
}
|
|
7
8
|
/** Define a valid boolean. */
|
|
8
9
|
export declare class BooleanSchema extends Schema<boolean> {
|
|
9
10
|
readonly value: boolean;
|
|
10
|
-
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
constructor({ value, required, ...options }: BooleanSchemaOptions);
|
|
11
13
|
validate(unsafeValue?: unknown): boolean;
|
|
12
14
|
}
|
|
13
15
|
/** Valid boolean. */
|
package/schema/BooleanSchema.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { Feedback } from "../feedback/Feedback.js";
|
|
1
2
|
import { Schema } from "./Schema.js";
|
|
2
3
|
const NEGATIVE = ["", "false", "0", "no", "n", "off"];
|
|
3
4
|
/** Define a valid boolean. */
|
|
4
5
|
export class BooleanSchema extends Schema {
|
|
5
|
-
constructor({ value = false, ...options }) {
|
|
6
|
+
constructor({ value = false, required = false, ...options }) {
|
|
6
7
|
super({ value, ...options });
|
|
8
|
+
this.required = required;
|
|
7
9
|
}
|
|
8
10
|
validate(unsafeValue = this.value) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const value = typeof unsafeValue === "string" ? !NEGATIVE.includes(unsafeValue.toLowerCase().trim()) : !!unsafeValue;
|
|
12
|
+
if (this.required && !value)
|
|
13
|
+
throw new Feedback("Required");
|
|
14
|
+
return value;
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
/** Valid boolean. */
|