diff --git a/src/const.ts b/src/const.ts index 48e56bb..09c6878 100644 --- a/src/const.ts +++ b/src/const.ts @@ -9,21 +9,22 @@ export type SweetId = string & { export const BLOCK_SIZE = 6; export const BlockCount = { - short: 1, - s: 1, - medium: 2, - m: 2, - long: 4, - l: 4, - xlong: 8, - xl: 8, + xshort: 1, + xs: 1, + short: 2, + s: 2, + medium: 4, + m: 4, + long: 8, + l: 8, + xlong: 16, + xl: 16, } as const; export type SweetIdSize = keyof typeof BlockCount; export const CharSets = { - Alphanumeric: - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + Alphanumeric: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", Decimal: "0123456789", } as const; @@ -35,6 +36,6 @@ export const options: ParseOptions = { default: { count: 1, - size: "short", + size: "xshort", }, }; diff --git a/src/main.ts b/src/main.ts index dc6cef5..badd331 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import { SweetId, SweetIdSize } from "./const.ts"; import { generate, getIdLength, validate } from "./utils.ts"; -export function sweetid(size: SweetIdSize = "short"): SweetId { +export function sweetid(size: SweetIdSize = "xs"): SweetId { const id = generate(getIdLength(size)); return validate(id) ? id : sweetid(size); diff --git a/src/utils.ts b/src/utils.ts index 20d7f0e..54df712 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import { customAlphabet } from "../deps.ts"; -import { BLOCK_SIZE, BlockCount, CharSets, SweetId, SweetIdSize } from "./const.ts"; +import { BLOCK_SIZE, BlockCount, CharSets, type SweetId, type SweetIdSize } from "./const.ts"; export function generate(length: number): SweetId { return customAlphabet(CharSets.Alphanumeric, length)(); @@ -10,5 +10,5 @@ export function validate(id: SweetId): boolean { } export function getIdLength(size: SweetIdSize): number { - return BlockCount[size] ? BLOCK_SIZE * BlockCount[size] : BLOCK_SIZE; + return (BlockCount[size] ?? 1) * BLOCK_SIZE; } diff --git a/test.ts b/test.ts index a6c9db9..ca92929 100644 --- a/test.ts +++ b/test.ts @@ -1,15 +1,17 @@ import { assertStrictEquals } from "https://deno.land/std@0.220.1/testing/asserts.ts"; -import { sweetid, SweetIdSize } from "./mod.ts"; +import { sweetid, type SweetIdSize } from "./mod.ts"; const tests = [ - { type: "short", size: 6 }, - { type: "s", size: 6 }, - { type: "medium", size: 12 }, - { type: "m", size: 12 }, - { type: "long", size: 24 }, - { type: "l", size: 24 }, - { type: "xlong", size: 48 }, - { type: "xl", size: 48 }, + { type: "xshort", size: 6 }, + { type: "xs", size: 6 }, + { type: "short", size: 12 }, + { type: "s", size: 12 }, + { type: "medium", size: 24 }, + { type: "m", size: 24 }, + { type: "long", size: 48 }, + { type: "l", size: 48 }, + { type: "xlong", size: 96 }, + { type: "xl", size: 96 }, ] as const satisfies ReadonlyArray<{ type: SweetIdSize; size: number }>; tests.forEach(({ type, size }) => {