Utilities
ZBSearch exposes some of its internal utility functions.
ZBSearch exposes some of its internal utility functions:
import {
boundedLevenshtein,
sprintf,
formatBytes,
formatNanoseconds,
getNanosecondsTime,
uniqueId,
} from "zbsearch/internals";Every exposed method comes with its own type definition. Each method is an async function. This is mandatory to support usage in CommonJS.
boundedLevenshtein
Computes the Levenshtein distance between two strings (a, b), returning early with -1 if the distance is greater than the given tolerance. It assumes that tolerance >= ||a| - |b|| >= 0.
import { boundedLevenshtein } from "zbsearch/internals";
await boundedLevenshtein("moon", "lions", 3); // { isBounded: true, distance: 3 }formatBytes
Takes a BigInt as input and returns a human-readable string.
import { formatBytes } from "zbsearch/internals";
await formatBytes(1024); // '1 KB'formatNanoseconds
Takes a BigInt as input and returns a human-readable string.
import { formatNanoseconds } from "zbsearch/internals";
await formatNanoseconds(30000n); // '30μs'getNanosecondsTime
Gets the current time with nanoseconds-precision. Returns a BigInt.
import { getNanosecondsTime } from "zbsearch/internals";
await getNanosecondsTime(); // 1363500821581208nuniqueId
Returns a uniqueId for a document as a string.
import { uniqueId } from "zbsearch/internals";
await uniqueId(); // 37149225-243TypeScript
If you cannot use set moduleResolution to nodenext or node16 in the tsconfig.json, you can import internals directly from the main entrypoint:
import { internals } from "zbsearch";
await internals.boundedLevenshtein();