mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Add isNumber/number validator
This commit is contained in:
@@ -30,6 +30,11 @@ export function isString(value: unknown): value is string {
|
||||
return typeof value === "string";
|
||||
}
|
||||
|
||||
/** Asserts that `value` is a number. */
|
||||
export function isNumber(value: unknown): value is number {
|
||||
return typeof value === "number";
|
||||
}
|
||||
|
||||
/** Asserts that `value` is either a string or undefined. */
|
||||
export function isStringOrUndefined(
|
||||
value: unknown,
|
||||
@@ -55,6 +60,12 @@ export const string = {
|
||||
required: true,
|
||||
} as const satisfies Validator<string>;
|
||||
|
||||
/** A validator for number fields in schemas. */
|
||||
export const number = {
|
||||
validate: isNumber,
|
||||
required: true,
|
||||
} as const satisfies Validator<number>;
|
||||
|
||||
/** Transforms a validator to be optional. */
|
||||
export function optional<T>(validator: Validator<T>) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user