sqids-decode ( sqids id -- numbers )
Sqids: encode numbers into short, unique, URL-safe IDs

Prev:sqids-encode ( sqids numbers -- str )
Next:default-alphabet ( -- value )


Vocabulary
sqids

Inputs
sqidsa sqids encoder
ida string


Outputs
numbersa sequence


Word description
Decodes an ID back into the original sequence of non-negative integers, using the same alphabet as the encoder. Returns an empty sequence if the ID is empty or contains a character not in the encoder's alphabet. Decoding does not enforce the blocklist or minimum length, and multiple IDs can decode to the same numbers. Re-encode the result and compare it with the original ID to check whether it is canonical for the current configuration.

Definition


:: sqids-decode ( sqids id -- numbers )
sqids alphabet>> :> alphabet id
{ [ empty? not ] [ [ alphabet member? ] all? ] } 1&& [
id first alphabet index
:> offset alphabet offset cut swap append
reverse :> rotated
[ id rest rotated decode-numbers ] { } make
] [ { } ] if ;