Skip to content

Num.Int

Num / Int

Import

typescript
import { Num } from '@wollybeard/kit'

// Access via namespace
Num.Int.someFunction()
typescript
import * as Num from '@wollybeard/kit/num'

// Access via namespace
Num.Int.someFunction()

Functions

[F] is

typescript
(value: unknown): boolean

Parameters:

  • value - The value to check

Returns: True if value is an integer

Type predicate to check if value is an integer.

[F] from

typescript
(value: number): Int

Parameters:

  • value - The number to convert to Int

Returns: The value as an Int

Throws:

  • Error if value is not an integer

Construct an Int. Throws if the value is not an integer.

[F] tryFrom

typescript
(value: number): Int | null

Parameters:

  • value - The number to try converting

Returns: The Int or null

Try to construct an Int. Returns null if the value is not an integer.

[F] parse

typescript
(value: string): Int | null

Parameters:

  • value - The string to parse

Returns: The parsed Int or null

Parse a string to an Int. Uses parseInt with base 10.

[F] round

typescript
(value: number): Int

Parameters:

  • value - The number to round

Returns: The rounded integer

Round a number to the nearest integer. Uses standard rounding rules (0.5 rounds up).

Types

[∩] Int

typescript
type Int = number & { [IntBrand]: true }

Integer number.

Integers are whole numbers without fractional parts. They can be positive, negative, or zero. In JavaScript, integers are represented as floating-point numbers but are guaranteed to have no decimal part.