{ } qjs-modules

pointer

Source: quickjs-pointer.c — module exports Pointer and DereferenceError

A JSON-Pointer-like path object: an ordered list of atoms (keys/indices) used to address into nested data, with array-style manipulation.

Pointer

new Pointer(path)   // length 1

path may be a pointer string, an array of keys, or another Pointer.

Methods

MethodArgsDescription
deref(root)1Resolves the pointer against root, returning the addressed value (throws DereferenceError if missing).
toString()0Serializes to a pointer string.
toArray()0Returns the atoms as an array.
shift()0Removes and returns the first atom.
unshift(atom)1Prepends an atom.
pop()0Removes and returns the last atom.
push(atom)1Appends an atom.
values()0Iterates the atoms (also [Symbol.iterator]).
hier()0Returns the hierarchy of prefixes.
at(index)1Returns the atom at index.
concat(other)1Returns a new pointer with other appended.
slice(start, end)0Returns a sub-range pointer.
splice(...)0Array-style splice of atoms.
up(n)1Returns the pointer truncated by n levels (alias truncate).
down(...)0Extends the pointer downward.
equal(other)1Equality test.
compare(other)1Ordering comparison.
common(other)1Longest common prefix with other.
relativeTo(other)1Path relative to other.
startsWith(other) / endsWith(other)1Prefix/suffix tests.

Properties

PropertyKindDescription
lengthgetterNumber of atoms.
pathgetter/setterThe path as an array.
atomsgetterThe raw atom list.

Static functions

FunctionArgsDescription
from(value)1Builds a pointer from a string/array.
fromAtoms(atoms)1Builds from an atom list.
of(...keys)0Builds from argument keys.
ofAtoms(...atoms)0Builds from argument atoms.
isPointer(value)1Whether value is a Pointer.

DereferenceError

Error subclass thrown when deref fails. Read-only properties: message, pointer, root, pos.