From 315e4bd1cf3dd85a775f71b381853bfc0ebf898a Mon Sep 17 00:00:00 2001 From: Kerim Hudson Date: Thu, 11 Apr 2024 18:04:05 +0100 Subject: [PATCH] improve docs --- README.md | 19 +++++++++++++++++++ mod.ts | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99301be..cba0d9c 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,24 @@ NameTag is a simple username generator with a dictionary of safe words to use to ## How to use ```ts +import { nametag } from "https://deno.land/x/nametag@0.0.1/mod.ts"; +const friendlyName = nametag(); +``` + +Or with a configuration: + +```ts +import { + nametag, + type NametagConfig, +} from "https://deno.land/x/nametag@0.0.1/mod.ts"; + +const config: NametagConfig = { + words: 5, + delimiter: "_", + categories: ["adjectives", "food"], +}; + +const friendlyName = nametag(config); ``` diff --git a/mod.ts b/mod.ts index d816569..d33956e 100644 --- a/mod.ts +++ b/mod.ts @@ -4,7 +4,7 @@ const getRandomWord = (words: string[]) => { return words[Math.floor(Math.random() * words.length)]; }; -type Config = { +export type NametagConfig = { delimiter?: string; words?: number; categories?: ("animals" | "food" | "adjectives")[]; @@ -18,7 +18,7 @@ const inputVal = v.object({ delimiter: v.optional(v.string(), "-"), }); -const nametag = (config?: Config) => { +const nametag = (config?: NametagConfig) => { const { words, categories, delimiter } = v.parse(inputVal, config); const output = [];