Header menu logo ananoid

NanoId Module

Contains utilities for working with nano identifiers.

Functions and values

Function or value Description

NanoId.isEmpty nanoId

Full Usage: NanoId.isEmpty nanoId

Parameters:
Returns: bool

Returns true, when the given nanoId is zero-valued; otherwise, false.

nanoId : NanoId
Returns: bool

NanoId.length nanoId

Full Usage: NanoId.length nanoId

Parameters:
Returns: int

The number of characters in the given nanoId instance.

nanoId : NanoId
Returns: int

NanoId.ofDefaults ()

Full Usage: NanoId.ofDefaults ()

Parameters:
    () : unit

Returns: NanoId

Creates a new instance using the default alphabet and size (nb: the default alphabet is URL-friendly numbers, English letters, and symbols: A-Za-z0-9_- and the default size is 21).

() : unit
Returns: NanoId

NanoId.ofOptions alphabet size

Full Usage: NanoId.ofOptions alphabet size

Parameters:
    alphabet : Alphabet - The letters from which the new NanoId will be generated.
    size : int - The length of a generated identifier, in number of characters (note: negative values are changed to zero).

Returns: NanoId

Creates a new NanoId instance of the given size whose letters are taken from the given alphabet.

alphabet : Alphabet

The letters from which the new NanoId will be generated.

size : int

The length of a generated identifier, in number of characters (note: negative values are changed to zero).

Returns: NanoId

NanoId.parseAs alphabet value

Full Usage: NanoId.parseAs alphabet value

Parameters:
    alphabet : Alphabet - The letters to check against for validity.
    value : string - The raw string to be converted.

Returns: NanoId option On successful parsing, returns a NanoId instance; otherwise, returns None.

Attempts to convert the given value into a NanoId, using the given alphabet to guide validation.

If the given value is empty (ie: null, zero-length, or consists only of whitespace), parsing will succeed (ie: return Some nanoId). However, the resulting NanoId instance will be NanoId.Empty.

alphabet : Alphabet

The letters to check against for validity.

value : string

The raw string to be converted.

Returns: NanoId option

On successful parsing, returns a NanoId instance; otherwise, returns None.

NanoId.parseNonEmptyAs alphabet value

Full Usage: NanoId.parseNonEmptyAs alphabet value

Parameters:
    alphabet : Alphabet - The letters to check against for validity.
    value : string - The raw string to be converted.

Returns: NanoId option On successful parsing, returns a NanoId instance; otherwise, returns None.

Attempts to convert the given value into a NanoId, using the given alphabet to guide validation.

Parsing will "fail" (ie: return None) if the given value is empty (ie: null, zero-length, or consists only of whitespace).

alphabet : Alphabet

The letters to check against for validity.

value : string

The raw string to be converted.

Returns: NanoId option

On successful parsing, returns a NanoId instance; otherwise, returns None.

Type something to start searching.