Skip to content

Appsweet-co/sweetid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, 48, or 96 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("short" || "s");
// => bzAuoVKRo1rJ

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

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

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

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 xs
# HrcZ9u

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

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

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

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

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 m -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.