Header menu logo ananoid

Alphabet Module

Contains utilities for working with alphabets.

Functions and values

Function or value Description

Alphabet.makeNanoId size alphabet

Full Usage: Alphabet.makeNanoId size alphabet

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

Returns: NanoId

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

size : int

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

alphabet : Alphabet

The letters from which the new NanoId will be generated.

Returns: NanoId

Alphabet.makeOrRaise letters

Full Usage: Alphabet.makeOrRaise letters

Parameters:
    letters : string - The letter set which will ultimately be used to generate NanoId instances.

Returns: Alphabet

Builds a new Alphabet from the given letter set after checking that it upholds certain invariants which are necessary for the algorithm to work well.

An alphabet's letters MUST uphold the following invariants:

  • Is not null
  • Contains at least one (1) non-whitespace letter
  • Contains no more then 255 letters

letters : string

The letter set which will ultimately be used to generate NanoId instances.

Returns: Alphabet
InvalidAlphabetException Raised when the given alphabet fails to uphold an invariant.

Alphabet.ofLetters letters

Full Usage: Alphabet.ofLetters letters

Parameters:
    letters : string - The letter set which will ultimately be used to generate NanoId instances.

Returns: Result<Alphabet, InvalidAlphabet> On successful validation, returns a Alphabet; otherwise, returns a InvalidAlphabet with further details about what went wrong.

Builds a new Alphabet from the given letter set after checking that it upholds certain invariants which are necessary for the algorithm to work well.

An alphabet's letters MUST uphold the following invariants:

  • Is not null
  • Contains at least one (1) non-whitespace letter
  • Contains no more then 255 letters

letters : string

The letter set which will ultimately be used to generate NanoId instances.

Returns: Result<Alphabet, InvalidAlphabet>

On successful validation, returns a Alphabet; otherwise, returns a InvalidAlphabet with further details about what went wrong.

Alphabet.parseNanoId value alphabet

Full Usage: Alphabet.parseNanoId value alphabet

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

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

Attempts to convert the given value into a NanoId, using a valid 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.

value : string

The raw string to be converted.

alphabet : Alphabet

The letters to check against for validity.

Returns: NanoId option

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

Alphabet.parseNonEmptyNanoId value alphabet

Full Usage: Alphabet.parseNonEmptyNanoId value alphabet

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

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

Attempts to convert the given value into a NanoId, using a valid 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).

value : string

The raw string to be converted.

alphabet : Alphabet

The letters to check against for validity.

Returns: NanoId option

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

Type something to start searching.