Puid.Chars (puid v2.0.1)

Pre-defined character sets for use when creating Puid modules.

example

Example

iex> defmodule(AlphanumId, do: use(Puid, chars: :alphanum))

pre-defined-chars

Pre-defined Chars

alpha

:alpha

Upper/lower case alphabet

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

alpha_lower

:alpha_lower

Lower case alphabet

abcdefghijklmnopqrstuvwxyz

alpha_upper

:alpha_upper

Upper case alphabet

ABCDEFGHIJKLMNOPQRSTUVWXYZ

alphanum

:alphanum

Upper/lower case alphabet and numbers

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

alphanum_lower

:alphanum_lower

Lower case alphabet and numbers

abcdefghijklmnopqrstuvwxyz0123456789

alphanum_upper

:alphanum_upper

Upper case alphabet and numbers

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

base32

:base32

RFC 4648 base32 character set

ABCDEFGHIJKLMNOPQRSTUVWXYZ234567

base32_hex

:base32_hex

RFC 4648 base32 extended hex character set with lowercase letters

0123456789abcdefghijklmnopqrstuv

base32_hex_upper

:base32_hex_upper

RFC 4648 base32 extended hex character set

0123456789ABCDEFGHIJKLMNOPQRSTUV

decimal

:decimal

Decimal digits

0123456789

hex

:hex

Lowercase hexadecimal

0123456789abcdef

hex_upper

:hex_upper

Uppercase hexadecimal

0123456789ABCDEF

safe_ascii

:safe_ascii

ASCII characters from ?! to ?~, minus backslash, backtick, single-quote and double-quote

`!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_bcdefghijklmnopqrstuvwxyz{|}~`

safe32

:safe32

Strings that don't look like English words and are easy to parse visually

2346789bdfghjmnpqrtBDFGHJLMNPQRT
  • remove all upper and lower case vowels (including y)
  • remove all numbers that look like letters
  • remove all letters that look like numbers
  • remove all letters that have poor distinction between upper and lower case values

safe64

:safe64

RFC 4648 file system and URL safe character set

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_

symbol

:symbol

:safe_ascii characters not in :alphanum

`!#$%&()*+,-./:;<=>?@[]^_{|}~`

Link to this section Summary

Types

Chars can be designated by a pre-defined atom, a binary or a charlist

Character encoding scheme. :ascii encoding uses cross-product character pairs.

Functions

Same as charlist/1 but either returns charlist or raises a Puid.Error

charlist for a pre-defined Puid.Chars, a String.t() or a charlist.

Link to this section Types

Link to this type

puid_chars()

@type puid_chars() :: atom() | String.t() | charlist()

Chars can be designated by a pre-defined atom, a binary or a charlist

Link to this type

puid_encoding()

@type puid_encoding() :: :ascii | :utf8

Character encoding scheme. :ascii encoding uses cross-product character pairs.

Link to this section Functions

Link to this function

charlist!(chars)

@spec charlist!(puid_chars()) :: charlist() | Puid.Error.t()

Same as charlist/1 but either returns charlist or raises a Puid.Error

example

Example

iex> Puid.Chars.charlist!(:safe32)
'2346789bdfghjmnpqrtBDFGHJLMNPQRT'

iex> Puid.Chars.charlist!("dingosky")
'dingosky'

iex> Puid.Chars.charlist!("unique")
# (Puid.Error) Characters not unique
Link to this function

charlist(chars)

@spec charlist(puid_chars()) :: {:ok, charlist()} | Puid.Error.t()

charlist for a pre-defined Puid.Chars, a String.t() or a charlist.

The characters for either String.t() or charlist types must be unique and must have more than one character. It is assumed each character has equal probability of occurrence, which maximizes entropy.

example

Example

iex> Puid.Chars.charlist(:safe32)
{:ok, '2346789bdfghjmnpqrtBDFGHJLMNPQRT'}

iex> Puid.Chars.charlist("dingosky")
{:ok, 'dingosky'}

iex> Puid.Chars.charlist("unique")
{:error, "Characters not unique"}