Skip to content

Commit 51d51e8

Browse files
committed
Add boolean Validator to json module
1 parent e893985 commit 51d51e8

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/json/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export function isNumber(value: unknown): value is number {
3535
return typeof value === "number";
3636
}
3737

38+
/** Asserts that `value` is a boolean. */
39+
export function isBoolean(value: unknown): value is boolean {
40+
return typeof value === "boolean";
41+
}
42+
3843
/** Asserts that `value` is either a string or undefined. */
3944
export function isStringOrUndefined(
4045
value: unknown,
@@ -79,6 +84,9 @@ export const string = makeValidator(isString);
7984
/** A validator for number fields in schemas. */
8085
export const number = makeValidator(isNumber);
8186

87+
/** A validator for boolean fields in schemas. */
88+
export const boolean = makeValidator(isBoolean);
89+
8290
/** A validator for arrays. */
8391
export function array<T>(validator: Validator<T>) {
8492
const validate = (val: unknown) => {

0 commit comments

Comments
 (0)