Skip to content

Latest commit

 

History

History
711 lines (356 loc) · 14.7 KB

NumberParser.md

File metadata and controls

711 lines (356 loc) · 14.7 KB

tsukikoDocs


tsukiko / NumberParser

Class: NumberParser

Represents a parser for number values with various validation options.

Extends

Constructors

new NumberParser()

new NumberParser(): NumberParser

Creates a new instance of NumberParser.

Returns

NumberParser

Overrides

Parser.constructor

Defined in

src/parsers/number.ts:73

Properties

defaultValue?

protected optional defaultValue: number

Inherited from

Parser.defaultValue

Defined in

src/parser.ts:49


isOptional

protected isOptional: boolean = false

Inherited from

Parser.isOptional

Defined in

src/parser.ts:44


langType

protected langType: langType = DEFAULT_LANG

Inherited from

Parser.langType

Defined in

src/utils/lang.ts:6


rules

protected rules: ParserFunction[]

Overrides

Parser.rules

Defined in

src/parsers/number.ts:44

Methods

check()

check(input): input is number

Checks if the input is valid according to the parser's rules.

Parameters

input: unknown

The input to check.

Returns

input is number

True if the input is valid, false otherwise.

Inherited from

Parser.check

Defined in

src/parser.ts:99


default()

default(value): Parser<number>

Sets a default value for the parser.

Parameters

value: number

The default value.

Returns

Parser<number>

The current Parser instance.

Inherited from

Parser.default

Defined in

src/parser.ts:118


defaultHandle()

protected defaultHandle(input): number

Parameters

input: number

Returns

number

Inherited from

Parser.defaultHandle

Defined in

src/parser.ts:34


describe()

describe(description): NumberParser

Sets a description for the parser.

Parameters

description: string

The description to set.

Returns

NumberParser

The current Parser instance.

Inherited from

Parser.describe

Defined in

src/parser.ts:138


empty()

empty(): NumberParser

Configures the parser to allow undefined but not null.

Returns

NumberParser

The current Parser instance.

Inherited from

Parser.empty

Defined in

src/parser.ts:128


error()

protected error(lang, data?): TsuError

Parameters

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?

Returns

TsuError

Inherited from

Parser.error

Defined in

src/parser.ts:39


even()

even(): NumberParser

Configures the parser to only accept even numbers.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:139


int()

int(): NumberParser

Configures the parser to only accept integer values.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:120


lang()

lang(value): NumberParser

Parameters

value: langType = DEFAULT_LANG

Returns

NumberParser

Inherited from

Parser.lang

Defined in

src/utils/lang.ts:8


max()

max(value, exclusive): NumberParser

Sets the maximum value (inclusive or exclusive) for the number.

Parameters

value: number

The maximum value.

exclusive: boolean = false

Whether the maximum is exclusive. Defaults to false.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:84


min()

min(value, exclusive): NumberParser

Sets the minimum value (inclusive or exclusive) for the number.

Parameters

value: number

The minimum value.

exclusive: boolean = false

Whether the minimum is exclusive. Defaults to false.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:97


multiple()

multiple(rate): NumberParser

Configures the parser to only accept multiples of a specified rate.

Parameters

rate: number

The rate of which the number must be a multiple.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:149


natural()

natural(): NumberParser

Configures the parser to only accept natural numbers (non-negative integers).

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:159


negative()

negative(): NumberParser

Configures the parser to only accept negative numbers (less than zero).

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:176


odd()

odd(): NumberParser

Configures the parser to only accept odd numbers.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:130


optional()

optional(): Parser<undefined | number>

Makes the parser optional.

Returns

Parser<undefined | number>

The current Parser instance.

Inherited from

Parser.optional

Defined in

src/parser.ts:107


parse()

parse(input): number

Parses the input and returns the result.

Parameters

input: unknown

The input to parse.

Returns

number

The parsed result.

Throws

If parsing fails.

Inherited from

Parser.parse

Defined in

src/parser.ts:61


parseAsync()

parseAsync(input): Promise<unknown>

Asynchronously parses the input.

Parameters

input: unknown

The input to parse.

Returns

Promise<unknown>

A promise that resolves with the parsed result or rejects with an error.

Inherited from

Parser.parseAsync

Defined in

src/parser.ts:86


parseSafe()

parseSafe(input): ParserSafeReturn<number>

Safely parses the input and returns a result object.

Parameters

input: unknown

The input to parse.

Returns

ParserSafeReturn<number>

An object containing the parsing result or error.

Inherited from

Parser.parseSafe

Defined in

src/parser.ts:72


percent()

percent(): NumberParser

Configures the parser to only accept percentages (numbers between 0 and 100 inclusive).

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:184


port()

port(): NumberParser

Configures the parser to only accept valid port numbers (integers between 1 and 65535 inclusive).

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:192


positive()

positive(): NumberParser

Configures the parser to only accept positive numbers (greater than zero).

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:168


range()

range(min, max, exclusiveMin, exclusiveMax): NumberParser

Sets both the minimum and maximum values for the number.

Parameters

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.

Returns

NumberParser

The current NumberParser instance.

Defined in

src/parsers/number.ts:112


schema()

schema(bringSchema): JsonSchema

Generates a JSON schema for the parser.

Parameters

bringSchema: boolean = true

Whether to include the $schema property. Defaults to true.

Returns

JsonSchema

The generated JSON schema.

Inherited from

Parser.schema

Defined in

src/parser.ts:158


setMeta()

protected setMeta(metadata): void

Parameters

metadata: Partial<SchemaMetadata>

Returns

void

Inherited from

Parser.setMeta

Defined in

src/parser.ts:51


title()

title(title): NumberParser

Sets a title for the parser.

Parameters

title: string

The title to set.

Returns

NumberParser

The current Parser instance.

Inherited from

Parser.title

Defined in

src/parser.ts:148