This documentation provides the usage of RowID.
Install this package as a dependency in the project:
# npm
npm i rowid
# Yarn
yarn add rowid
# pnpm
pnpm add rowid
# Deno
deno add npm:rowid
# Bun
bun add rowid
RowID provides the following functions:
This function generates a 32-character unique ID that is almost impossible to duplicate.
Or you can specify the number of randomness, a larger number will generate a longer ID, with less chance of collision.
Example:
import RowID from "rowid";
const id: string = RowID();
With specified randomness:
import RowID from "rowid";
const id: string = RowID(6);
This function encodes the timestamp into a ID without randomness.
Example:
import { encode } from "rowid";
const result: string = encode(new Date().getTime());
This function decodes the ID into a Date.
Example:
import { RowID, decode } from "rowid";
const id: string = RowID();
const result: Date = decode(id);
This function generates a ID based on the input.
Example:
import type { GenerateResult } from "rowid";
import { generate } from "rowid";
const current: number = new Date().getTime();
const result: GenerateResult = generate(current, 22);
This function verifies if the ID is valid and natural.
Example:
import type { VerifyResult } from "rowid";
import { RowID, verify } from "rowid";
const id: string = RowID();
const result: VerifyResult = verify(id);
This function generates randomness with different methods based on the environment.
Example:
import { getRandomness } from "rowid";
const result: string = getRandomness(6);
This function allows you to customize how RowID works, and returns the modified functions based on the parameters.
Example:
import type { RowIDWithConfigResult } from "rowid";
import { RowIDWithConfig } from "rowid";
const {
RowID,
encode,
decode,
generate,
verify,
getRandomness,
}: RowIDWithConfigResult = RowIDWithConfig({
// ...
});