diff --git a/deno.json b/deno.json index e96cddf..473e10e 100644 --- a/deno.json +++ b/deno.json @@ -1,10 +1,14 @@ { - "version": "0.0.4", - "name": "@baosoy/nametag", + "version": "0.0.5", "$schema": "http://json-schema.org/draft-07/schema", + "name": "@baosoy/nametag", + "exports": "./mod.ts", "description": "A simple friendly username generator", "tasks": { "dev": "deno run --watch main.ts", "test": "deno test mod_tests.ts" + }, + "imports": { + "@valibot/valibot": "jsr:@valibot/valibot@^0.30.0" } } diff --git a/deno.lock b/deno.lock index b3e873b..f86bfec 100644 --- a/deno.lock +++ b/deno.lock @@ -1,5 +1,15 @@ { "version": "3", + "packages": { + "specifiers": { + "jsr:@valibot/valibot@^0.30.0": "jsr:@valibot/valibot@0.30.0" + }, + "jsr": { + "@valibot/valibot@0.30.0": { + "integrity": "a0a8701bc789a7bf91bff22308c590c22ac7d6076617289b04125490954bebe2" + } + } + }, "remote": { "https://deno.land/std@0.163.0/fmt/colors.ts": "9e36a716611dcd2e4865adea9c4bec916b5c60caad4cdcdc630d4974e6bb8bd4", "https://deno.land/std@0.163.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c", @@ -378,5 +388,10 @@ "https://deno.land/x/valibot@v0.30.0/src/validations/uuid/uuid.ts": "3fd12ef01a38b02ab8cf05a69ec1935e4e85603f9063ca58ee4e57ba90a27c94", "https://deno.land/x/valibot@v0.30.0/src/validations/value/index.ts": "5d0815e3877c5e4548b222597d37fd277f46044193039c7a42539af34e655914", "https://deno.land/x/valibot@v0.30.0/src/validations/value/value.ts": "888902cb5747629250cac155b56a530572bd76b3df2f09360643312496374adc" + }, + "workspace": { + "dependencies": [ + "jsr:@valibot/valibot@^0.30.0" + ] } } diff --git a/deps.ts b/deps.ts index 1a0b1cd..23aa1fc 100644 --- a/deps.ts +++ b/deps.ts @@ -1,2 +1,3 @@ -import * as v from "https://deno.land/x/valibot@v0.30.0/mod.ts"; -export { v }; +import * as v from "@valibot/valibot"; +import type { BaseSchema } from "@valibot/valibot"; +export { v, type BaseSchema }; diff --git a/mod.ts b/mod.ts index 36fb511..1038553 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,6 @@ import * as dictionary from "./words.ts"; -import { v } from "./deps.ts"; -const getRandomWord = (words: string[]) => { +import { v, type BaseSchema } from "./deps.ts"; +const getRandomWord = (words: string[]): string => { return words[Math.floor(Math.random() * words.length)]; }; @@ -22,10 +22,17 @@ const inputVal = v.optional( categories: ["animals", "food", "adjectives"], words: 3, delimiter: "-", - }, -); + } +) as BaseSchema< + NametagConfig, + { + delimiter: string; + categories: string[]; + words: number; + } +>; -const nametag = (config?: NametagConfig) => { +export const nametag = (config?: NametagConfig): string => { const { words, categories, delimiter } = v.parse(inputVal, config); const output = []; @@ -41,8 +48,8 @@ const nametag = (config?: NametagConfig) => { categories[ Math.floor(Math.random() * length) ] as keyof typeof dictionary - ], - ), + ] + ) ); } else { output.push( @@ -51,8 +58,8 @@ const nametag = (config?: NametagConfig) => { categories[ Math.floor(Math.random() * categories.length) ] as keyof typeof dictionary - ], - ), + ] + ) ); } } else { @@ -62,13 +69,11 @@ const nametag = (config?: NametagConfig) => { categories[ Math.floor(Math.random() * categories.length) ] as keyof typeof dictionary - ], - ), + ] + ) ); } } return output.join(delimiter); }; - -export { nametag };