object

sqids(Representation)

  • Representation - Text representation for identifiers. Possible values are atom, chars, and codes.

Encoding and decoding of short, obfuscated, URL-safe ids from lists of non-negative integers, per the Sqids specification.

Availability:
logtalk_load(sqids(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-08-09
Compilation flags:
static, context_switching_calls
Imports:
public options
Uses:
Remarks:

Public predicates

encode/2

Encodes a list of non-negative integers into an identifier using the default options.

Compilation flags:
static
Template:
encode(Numbers,Id)
Mode and number of proofs:
encode(+list(integer),-text) - one
Exceptions:
Numbers is a variable or a partial list:
instantiation_error
Numbers is neither a variable nor a list:
type_error(list(non_negative_integer),Numbers)
An element Number of the list Numbers is not an integer:
type_error(integer,Number)
An element Number of the list Numbers of Numbers is a negative integer:
domain_error(non_negative_integer,Number)
Too many blocklist collisions occurred while generating the id:
resource_error(blocklist_retries)

encode/3

Encodes a list of non-negative integers into an id using the given options. Recognized options are alphabet(Atom) (an atom with at least three unique characters; default is the standard 62-character alphabet), min_length(Integer) (an integer between 0 and 255; default is 0), and blocklist(list(atom)) (words that must not occur in the generated id; default is []). If Numbers is empty, Id is unified with the empty atom regardless of the other options.

Compilation flags:
static
Template:
encode(Numbers,Id,Options)
Mode and number of proofs:
encode(+list(integer),-text,+list(compound)) - one_or_error
Exceptions:
Numbers is a variable or a partial list:
instantiation_error
Numbers is neither a variable nor a list:
type_error(list(non_negative_integer),Numbers)
An element Number of the list Numbers is not an integer:
type_error(integer,Number)
An element Number of the list Numbers of Numbers is a negative integer:
domain_error(non_negative_integer,Number)
Options is a variable or a partial list:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)
Too many blocklist collisions occurred while generating the id:
resource_error(blocklist_retries)

decode/2

Decodes an identifier back into a list of non-negative integers using the default options. Equivalent to decode/3 with an empty options list. Numbers is [] if Id is the empty atom or contains a character that is not in the alphabet. Decoding does not check that Id is a canonical (minimal) encoding: ids rejected by encode/2-3 due to the blocklist still decode successfully, as do ids with extraneous minimum-length padding.

Compilation flags:
static
Template:
decode(Id,Numbers)
Mode and number of proofs:
decode(+text,-list(integer)) - one_or_error
Exceptions:
Id is a variable:
instantiation_error
Id is neither a variable nor an atom:
type_error(atom,Id)

decode/3

Decodes an identifier back into a list of non-negative integers using the given options. The only recognized option is alphabet(Atom); it must be the same alphabet that was used to encode Id. Numbers is [] if Id is the empty atom or contains a character that is not in the alphabet.

Compilation flags:
static
Template:
decode(Id,Numbers,Options)
Mode and number of proofs:
decode(+text,-list(integer),+list(compound)) - one_or_error
Exceptions:
Id is a variable:
instantiation_error
Id is neither a variable nor an atom:
type_error(atom,Id)
Options is a variable or a partial list:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)

Protected predicates

(no local declarations; see entity ancestors if any)

Private predicates

(no local declarations; see entity ancestors if any)

Operators

(none)