types

The types module provides runtime type inspection and value conversion. Top-level helpers check a value’s type, while submodules group parsing, formatting, and predicates for each primitive type. Import it with import types.

Top-level

FunctionSignatureDescription
isStringtypes.isString(v: any) → boolWhether v is a string
isInttypes.isInt(v: any) → boolWhether v is an int
isFloattypes.isFloat(v: any) → boolWhether v is a float
isBooltypes.isBool(v: any) → boolWhether v is a bool
isArraytypes.isArray(v: any) → boolWhether v is an array
isVoidtypes.isVoid(v: any) → boolWhether v is void/null
typeOftypes.typeOf(v: any) → stringName of the value’s type

types.int

FunctionSignatureDescription
parsetypes.int.parse(s: string) → intParse a decimal int, 0 on failure
toBintypes.int.toBin(n: int) → stringBinary form with 0b prefix
toHextypes.int.toHex(n: int) → stringHex form with 0x prefix
toOcttypes.int.toOct(n: int) → stringOctal form with 0o prefix
fromBintypes.int.fromBin(s: string) → intParse binary (optional 0b), 0 on failure
fromHextypes.int.fromHex(s: string) → intParse hex (optional 0x), 0 on failure
fromOcttypes.int.fromOct(s: string) → intParse octal (optional 0o), 0 on failure
maxtypes.int.max() → intLargest representable int
mintypes.int.min() → intSmallest representable int
isInttypes.int.isInt(v: any) → boolWhether v is an int

types.float

FunctionSignatureDescription
parsetypes.float.parse(s: string) → floatParse a float, 0.0 on failure
roundtypes.float.round(f: float, decimals: int) → floatRound to decimals places
toFixedtypes.float.toFixed(f: float, decimals: int) → stringFormat with a fixed number of decimals
isNaNtypes.float.isNaN(v: any) → boolWhether v is NaN
isInftypes.float.isInf(v: any) → boolWhether v is infinite
isFloattypes.float.isFloat(v: any) → boolWhether v is a float

types.bool

FunctionSignatureDescription
parsetypes.bool.parse(s: string) → boolParse true/1/yes/on as true
toStringtypes.bool.toString(b: bool) → string"true" or "false"
isBooltypes.bool.isBool(v: any) → boolWhether v is a bool

types.char

Each function takes a one-character string.

FunctionSignatureDescription
codetypes.char.code(c: string) → intByte code of the character
fromCodetypes.char.fromCode(code: int) → stringCharacter for the codepoint
isUppertypes.char.isUpper(c: string) → boolWhether the char is uppercase
isLowertypes.char.isLower(c: string) → boolWhether the char is lowercase
isDigittypes.char.isDigit(c: string) → boolWhether the char is a digit
isAlphatypes.char.isAlpha(c: string) → boolWhether the char is a letter
isSpacetypes.char.isSpace(c: string) → boolWhether the char is whitespace
toLowertypes.char.toLower(c: string) → stringLowercased char
toUppertypes.char.toUpper(c: string) → stringUppercased char

types.string

FunctionSignatureDescription
istypes.string.is(v: any) → boolWhether v is a string
emptytypes.string.empty(v: any) → boolWhether v is an empty string
nonEmptytypes.string.nonEmpty(v: any) → boolWhether v is a non-empty string
defaulttypes.string.default(v: any, default: string) → anyv unless it is void or empty, then default
coercetypes.string.coerce(v: any) → stringString form of any value
lengthtypes.string.length(v: any) → intByte length, 0 if not a string

types.null and types.void

FunctionSignatureDescription
istypes.null.is(v: any) → boolWhether v is null/void
valuetypes.null.valueThe null/void value
istypes.void.is(v: any) → boolWhether v is void
valuetypes.void.valueThe void value

Example

import types

let n = types.int.parse("255")
print(types.int.toHex(n))               // 0xff

let v = "hello"
print(types.typeOf(v))                  // string
print(types.string.default("", "fallback"))  // fallback
Standard library · View as Markdown · llms-full.txt