Creates a position between two others, to move or insert an item between its neighbors.
The room left in the N section is used first. When the positions are adjacent, the Z section
takes the middle value, making the position one digit longer. Moving items again and again into
the same gap makes positions grow until the threshold (ThresholdReachedError) and the overflow (OverflowError).
The position that must be before the new one (or a result with it).
The position that must be after the new one (or a result with it).
The position between previous and next, or the error (including a SystemMismatchError
if a position was created by a system with another configuration).
Creates a position from its string, for example one stored in a database.
When the string is shorter than the N section (ln characters), N is completed with zeroes
to the right, which keeps the string order ("xy" becomes "xy!!!!").
The string representation of the position.
The position, or the error: InvalidCharacterError for a character that is not a digit of the system,
OverflowError if it is too long, ThresholdReachedError if it reached the threshold.
Creates a position from its digits, the inverse of position.digits().
The digits are split in the N and Z sections of the system: N takes the ln most significant digits.
The digits of the position.
The position, or the error if it is too long (OverflowError) or reached the threshold (ThresholdReachedError).
Checks if the position is longer than the max length lmax = ln + lz of the system,
the condition of an OverflowError.
The position to check.
Checks if the length of the position reached the threshold lϰ = ceil((1 - fϰ) * lmax),
the condition of a ThresholdReachedError.
The position to check.
Creates the position right after another, to stack an item at the end of a list.
It adds 1 to the N section, so the position never gets longer. When N is already its
last value (every digit is last) it fails with an OverflowError.
The position to start from (or a result with it).
The next position, or the error.
Creates the position right before another, to stack an item at the start of a list.
It subtracts 1 from the N section, so the position never gets longer. When N is already
its first value (every digit is zero) it fails with an OverflowError.
The position to start from (or a result with it).
The previous position, or the error.
Creates the recommended first position of a list: the middle digit repeated in the whole N section,
so there is the same room to stack items before and after it.
The start position.
StaticalphabetThe alphabet: ! as the zero and the lowercase letters from a to z (base 27). Readable positions, safe
in URLs, the system of every example of the documentation.
Optionaloptions: IPresetOptionsChanges the lengths, the threshold or the classes, see IPresetOptions.
StaticasciiPlain ASCII: ! as the zero and every printable character from # to ~ except ', \ and ` (base
90). The most compact choice per byte, and nothing to escape in JSON, SQL literals or logs.
Optionaloptions: IPresetOptionsChanges the lengths, the threshold or the classes, see IPresetOptions.
Staticbase36Base 36: 0 as the zero, the digits 1-9 and the lowercase letters (base 36). Safe with case insensitive
collations (the MySQL default) and where keys must be alphanumeric.
Optionaloptions: IPresetOptionsChanges the lengths, the threshold or the classes, see IPresetOptions.
StaticcreateCreates a number system. Its digits are the zero and every character from first to last,
so its base is b = (last - first) + 2 (by their unicode values).
Use characters of the Basic Multilingual Plane (up to U+FFFF), so JavaScript, UTF-8 and UTF-16
compare them in the same order. The characters must be zero < first < last.
The character of the zero digit.
The character of the first digit (1).
The character of the last digit (b - 1).
The fixed length of the N section, used to stack items without making positions longer.
The max length of the Z section, used when items are moved between two others.
A factor from 0 to 1: the threshold is reached at the length lϰ = ceil((1 - fϰ) * (ln + lz)).
Optionaloptions: IStaquiaOptionsReplaces the classes used to create positions and numbers, see IStaquiaOptions.
The Staquia system.
StaticdefaultCreates the default number system, ready for production: the zero !, the digits from
\u00B0 (°) to \u04B1 (ұ), a base 1027 system, with ln = 5, lz = 15 and fϰ = 0.15.
Optionaloptions: IPresetOptionsThe default Staquia system.
import Staquia from "staquia";
const system = Staquia.default();
// The same as
const same = Staquia.create("!", "\u00B0", "\u04B1", 5, 15, 0.15);
const start = system.start();
if (start.ok) console.log(start.value.toString()); // "ʰʰʰʰʰ!"
Try other settings for your project in the Setup App of the documentation.
StaticfromCreates a number system from a set of characters: the zero followed by every digit, sorted by their code, so
its base is the number of characters. Use it when the digits are not a range, for example to leave some
characters out; a set whose digits are consecutive is the same system as create with that range, and their
positions are compatible.
The characters must be sorted by their code without repeating any, and be in the Basic Multilingual Plane (up
to U+FFFF), so JavaScript, UTF-8 and UTF-16 compare them in the same order.
The zero followed by every digit, sorted by their code.
The fixed length of the N section.
The max length of the Z section.
A factor from 0 to 1: the threshold is reached at the length lϰ = ceil((1 - fϰ) * (ln + lz)).
Optionaloptions: IStaquiaOptionsReplaces the classes used to create positions and numbers, see IStaquiaOptions.
StaticurlURL safe: the characters of URL safe base64 (-, 0-9, A-Z, _, a-z) sorted by their code, - as
the zero (base 64). Positions go in URLs, file names and HTML ids without any encoding.
The characters are not in the base64 order: positions are sort keys, not encoded data, so they keep the order a database compares them in.
Optionaloptions: IPresetOptionsChanges the lengths, the threshold or the classes, see IPresetOptions.
A lexicographic number system that creates positions: short strings that keep the order of a list. Sort the items by their position string and you get the order back; moving an item only changes its own position.
Create one with
Staquia.create(orStaquia.default), then use it to create positions, or give it to aLexicalListto keep the positions of your objects in sync. Nothing is thrown: every function that can fail returns aResult.Example
Remarks
Read the guide at the Staquia documentation page.