Skip to content

Utilities

Orama exposes some of its internal utility functions:

import {
boundedLevenshtein,
sprintf,
formatBytes,
formatNanoseconds,
getNanosecondsTime,
uniqueId,
} from "@orama/orama/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 "@orama/orama/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 "@orama/orama/internals";
await formatBytes(1024); // '1 KB'

formatNanoseconds

Takes a BigInt as input and returns a human-readable string.

import { formatNanoseconds } from "@orama/orama/internals";
await formatNanoseconds(30000n); // '30μs'

getNanosecondsTime

Gets the current time with nanoseconds-precision. Returns a BigInt.

import { getNanosecondsTime } from "@orama/orama/internals";
await getNanosecondsTime(); // 1363500821581208n

uniqueId

Returns a uniqueId for a document as a string.

import { uniqueId } from "@orama/orama/internals";
await uniqueId(); // 37149225-243

TypeScript

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 "@orama/orama";
await internals.boundedLevenshtein();