Skip to content

Commit ffb3423

Browse files
committed
Add isNumber/number validator
1 parent 628fc3f commit ffb3423

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎src/json/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export function isString(value: unknown): value is string {
3030
return typeof value === "string";
3131
}
3232

33+
/** Asserts that `value` is a number. */
34+
export function isNumber(value: unknown): value is number {
35+
return typeof value === "number";
36+
}
37+
3338
/** Asserts that `value` is either a string or undefined. */
3439
export function isStringOrUndefined(
3540
value: unknown,
@@ -55,6 +60,12 @@ export const string = {
5560
required: true,
5661
} as const satisfies Validator<string>;
5762

63+
/** A validator for number fields in schemas. */
64+
export const number = {
65+
validate: isNumber,
66+
required: true,
67+
} as const satisfies Validator<number>;
68+
5869
/** Transforms a validator to be optional. */
5970
export function optional<T>(validator: Validator<T>) {
6071
return {

0 commit comments

Comments
 (0)