Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback

Logo

Sweet ID

Alphanumeric IDs, powered by Nano ID


GitHub release (latest SemVer)


Quick Start

Import sweetid() directly into your project.

import { sweetid } from "https://deno.land/x/foo/bar/baz@v0.0.4/mod.ts";

sweetid();
// => CUXuq1

Or use Sweet ID in the command line.

deno run https://deno.land/x/foo/bar/baz@v0.0.4/cli.ts
# buGdUo

Details

We use Nano ID under the hood to guarantee high-quality, cryptographically secure IDs.

Sweet ID are alphanumeric and always start with a letter.

ID Length

The sweetid() function generates IDs with a length 6, 12, 18, or 24 characters. IDs are 6 characters long by default.

Pass in an optional SweetIdSize as the first argument to set the output size of the ID.

sweetid("small" || "s");
// => hBuWX4

sweetid("medium" || "m");
// => b1eOHzXq6iK0

sweetid("long" || "l");
// => Rk3ulcSjeoyigV1zYn

sweetid("xlong" | "x");
// => CYhSN6DvdNZajwKhDjmdFXAD

Pass in the same SweetIdSize as an optional flag to set the output size on the command line.

deno run https://deno.land/x/foo/bar/baz@v0.0.4/cli.ts --small || -s
# PLmh1V

deno run https://deno.land/x/foo/bar/baz@v0.0.4/cli.ts --medium || -m
# so24iHcuI86i

deno run https://deno.land/x/foo/bar/baz@v0.0.4/cli.ts --long || -l
# lugJNFIFYYLWJ8SAnb

deno run https://deno.land/x/foo/bar/baz@v0.0.4/cli.ts --xlong || -x
# NsiHnUqK3cbADQ9cIzsi0Og0

TypeScript Types

Use SweetId and SweetIdSize to add type info to your project. This is great for things like custom wrapper functions.

import type {
  SweetId,
  SweetIdSize,
} from "https://deno.land/x/foo/bar/baz@v0.0.4/mod.ts";
import { sweetid } from "https://deno.land/x/foo/bar/baz@v0.0.4/mod.ts";

export function customSweetId(size: SweetIdSize = "medium"): SweetId {
  return sweetid(size);
}

***NOTE: SweetId is a flexible nominal type and will play nicely with generic string types if needed.