Logo

Sweet ID

Alphanumeric IDs, powered by Nano ID


GitHub release (latest SemVer)


Quick Start

Import mod.ts directly into your project.

import { sweetid } from "https://deno.land/x/sweetid/mod.ts";

sweetid();
// => CUXuq1

Or use Sweet ID in the command line.

deno run https://deno.land/x/sweetid/cli.ts
# buGdUo

Details

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

Sweet IDs are alphanumeric and always start with a letter.

ID Length

The sweetid() function generates IDs with a length 6, 12, 24, or 48 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("xshort" || "xs");
// => MkSofu

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

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

sweetid("xlong" | "xl");
// => dRjFNY7TrZFqizgKLBwWXAQSErCk51gheMFlBNVAZFM5DuLr

Use the --size <SweetIdSize> (-s <SweetIdSize>) flag on the command line to set the output size.

deno run https://deno.land/x/sweetid/cli.ts -s s
# HrcZ9u

deno run https://deno.land/x/sweetid/cli.ts -s m
# s75rHr14EJYJ

deno run https://deno.land/x/sweetid/cli.ts -s l
# rCJLcqqHW4yuvsSeGPH4INok

deno run https://deno.land/x/sweetid/cli.ts -s xl
# hMASSfdHZDbpZFHL2UZFWEduk6Ltt5OcxaidVcxXU1K0cyyD

Generate Multiple IDs

Use the --count <NUMBER> (-c <NUMBER>) flag on the command line to generate multiple IDs of the same length.

deno run https://deno.land/x/sweetid/cli.ts -c 3
# B4a6Xc
# uRYkkT
# NJZtjW

deno run https://deno.land/x/sweetid/cli.ts -s l -c 3
# hxzRSWPX5TDcQieHk2B7fPkA
# LXaAyksi6d3HgCAyw2Y4EKM8
# sZhCDNUjQRJzptbNqGco1HdL

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/sweetid/mod.ts";
import { sweetid } from "https://deno.land/x/sweetid/mod.ts";

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

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