Skip to content

Commit

Permalink
reorganise for jsr publication
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerim Hudson committed Apr 15, 2024
1 parent c882a7c commit b83f6e6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
8 changes: 6 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
15 changes: 15 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import * as v from "https://deno.land/x/[email protected]/mod.ts";
export { v };
import * as v from "@valibot/valibot";
import type { BaseSchema } from "@valibot/valibot";
export { v, type BaseSchema };
31 changes: 18 additions & 13 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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)];
};

Expand All @@ -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 = [];

Expand All @@ -41,8 +48,8 @@ const nametag = (config?: NametagConfig) => {
categories[
Math.floor(Math.random() * length)
] as keyof typeof dictionary
],
),
]
)
);
} else {
output.push(
Expand All @@ -51,8 +58,8 @@ const nametag = (config?: NametagConfig) => {
categories[
Math.floor(Math.random() * categories.length)
] as keyof typeof dictionary
],
),
]
)
);
}
} else {
Expand All @@ -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 };

0 comments on commit b83f6e6

Please sign in to comment.