tsukiko • Docs
tsukiko / NumberParser
Represents a parser for number values with various validation options.
Parser
<number
>
new NumberParser():
NumberParser
Creates a new instance of NumberParser.
protected
optional
defaultValue:number
protected
isOptional:boolean
=false
protected
langType:langType
=DEFAULT_LANG
protected
rules:ParserFunction
[]
check(
input
):input is number
Checks if the input is valid according to the parser's rules.
• input: unknown
The input to check.
input is number
True if the input is valid, false otherwise.
default(
value
):Parser
<number
>
Sets a default value for the parser.
• value: number
The default value.
Parser
<number
>
The current Parser instance.
protected
defaultHandle(input
):number
• input: number
number
describe(
description
):NumberParser
Sets a description for the parser.
• description: string
The description to set.
The current Parser instance.
empty():
NumberParser
Configures the parser to allow undefined but not null.
The current Parser instance.
protected
error(lang
,data
?):TsuError
• lang: "not_string"
| "not_a_email"
| "not_a_domain"
| "not_a_url"
| "illegal_match_string"
| "illegal_starts_with"
| "illegal_ends_with"
| "too_long"
| "too_short"
| "not_number"
| "not_integer_number"
| "not_odd_number"
| "not_even_number"
| "not_natural_number"
| "not_positive_number"
| "not_negative_number"
| "not_percentage"
| "too_bigger"
| "too_bigger_has"
| "too_smaller"
| "too_smaller_has"
| "not_multiple_number"
| "is_a_NaN"
| "not_boolean"
| "not_true"
| "not_false"
| "not_null"
| "not_undefined"
| "not_never"
| "not_an_array"
| "array_error"
| "too_many_items"
| "too_few_items"
| "not_a_tuple"
| "illegal_tuple_length"
| "tuple_error"
| "not_an_object"
| "object_is_null"
| "object_is_an_array"
| "object_not_instance_of_constructor"
| "object_keys_too_many"
| "object_keys_too_few"
| "object_error"
| "object_key_error"
| "intersection_error"
| "union_error"
| "literal_only"
| "literal_number_error"
| "literal_string_error"
| "literal_boolean_error"
| "custom_error"
| "not_a_function"
| "not_a_constructor"
| "not_an_async_function"
| "not_a_generator_function"
| "not_an_async_generator_function"
| "not_an_arrow_function"
| "function_args_count_mismatch"
| "function_name_mismatch"
| "not_a_class"
| "class_args_count_mismatch"
| "class_name_mismatch"
| "class_prototype_error"
• data?
even():
NumberParser
Configures the parser to only accept even numbers.
The current NumberParser instance.
int():
NumberParser
Configures the parser to only accept integer values.
The current NumberParser instance.
lang(
value
):NumberParser
• value: langType
= DEFAULT_LANG
max(
value
,exclusive
):NumberParser
Sets the maximum value (inclusive or exclusive) for the number.
• value: number
The maximum value.
• exclusive: boolean
= false
Whether the maximum is exclusive. Defaults to false.
The current NumberParser instance.
min(
value
,exclusive
):NumberParser
Sets the minimum value (inclusive or exclusive) for the number.
• value: number
The minimum value.
• exclusive: boolean
= false
Whether the minimum is exclusive. Defaults to false.
The current NumberParser instance.
multiple(
rate
):NumberParser
Configures the parser to only accept multiples of a specified rate.
• rate: number
The rate of which the number must be a multiple.
The current NumberParser instance.
natural():
NumberParser
Configures the parser to only accept natural numbers (non-negative integers).
The current NumberParser instance.
negative():
NumberParser
Configures the parser to only accept negative numbers (less than zero).
The current NumberParser instance.
odd():
NumberParser
Configures the parser to only accept odd numbers.
The current NumberParser instance.
optional():
Parser
<undefined
|number
>
Makes the parser optional.
Parser
<undefined
| number
>
The current Parser instance.
parse(
input
):number
Parses the input and returns the result.
• input: unknown
The input to parse.
number
The parsed result.
If parsing fails.
parseAsync(
input
):Promise
<unknown
>
Asynchronously parses the input.
• input: unknown
The input to parse.
Promise
<unknown
>
A promise that resolves with the parsed result or rejects with an error.
parseSafe(
input
):ParserSafeReturn
<number
>
Safely parses the input and returns a result object.
• input: unknown
The input to parse.
ParserSafeReturn
<number
>
An object containing the parsing result or error.
percent():
NumberParser
Configures the parser to only accept percentages (numbers between 0 and 100 inclusive).
The current NumberParser instance.
port():
NumberParser
Configures the parser to only accept valid port numbers (integers between 1 and 65535 inclusive).
The current NumberParser instance.
positive():
NumberParser
Configures the parser to only accept positive numbers (greater than zero).
The current NumberParser instance.
range(
min
,max
,exclusiveMin
,exclusiveMax
):NumberParser
Sets both the minimum and maximum values for the number.
• min: number
The minimum value.
• max: number
The maximum value.
• exclusiveMin: boolean
= false
Whether the minimum is exclusive. Defaults to false.
• exclusiveMax: boolean
= false
Whether the maximum is exclusive. Defaults to false.
The current NumberParser instance.
schema(
bringSchema
):JsonSchema
Generates a JSON schema for the parser.
• bringSchema: boolean
= true
Whether to include the $schema property. Defaults to true.
The generated JSON schema.
protected
setMeta(metadata
):void
• metadata: Partial
<SchemaMetadata
>
void
title(
title
):NumberParser
Sets a title for the parser.
• title: string
The title to set.
The current Parser instance.