namelet 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -8,6 +8,6 @@ interface NameOpts {
8
8
  }
9
9
  //#endregion
10
10
  //#region src/create-name.d.ts
11
- declare function createName({ wordLists, separator, casing }: NameOpts): string;
11
+ declare function createName(options: NameOpts): string;
12
12
  //#endregion
13
13
  export { type Casing, type NameOpts, type WordLists, createName };
package/dist/index.mjs CHANGED
@@ -7449,24 +7449,38 @@ const dictionaries = {
7449
7449
  "Zam Wesell"
7450
7450
  ]
7451
7451
  };
7452
- function createName({ wordLists, separator = "-", casing = "lowerCase" }) {
7453
- const name = wordLists.map((list) => {
7454
- const word = pickWord(dictionaries[list]);
7455
- return (casing === "capital" ? casingFmt(word, casing) : word).split(" ").join(separator);
7456
- }).join(separator);
7457
- return casing === "capital" ? name : casingFmt(name, casing);
7458
- }
7459
- function pickWord(words) {
7460
- if (words.length === 0) throw new Error("Cannot pick from an empty word list");
7461
- return words[Math.floor(Math.random() * words.length)];
7462
- }
7463
- function casingFmt(word, casing) {
7464
- switch (casing) {
7465
- case "upperCase": return word.toUpperCase();
7466
- case "lowerCase": return word.toLowerCase();
7467
- case "capital": return word.split(" ").map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join(" ");
7468
- default: return word;
7452
+ var Namelet = class {
7453
+ options;
7454
+ constructor({ wordLists, separator = "-", casing = "lowerCase" }) {
7455
+ this.options = {
7456
+ wordLists: [...wordLists],
7457
+ separator,
7458
+ casing
7459
+ };
7460
+ }
7461
+ generate() {
7462
+ const { wordLists, separator, casing } = this.options;
7463
+ const name = wordLists.map((list) => {
7464
+ const word = this.pickWord(dictionaries[list]);
7465
+ return (casing === "capital" ? this.casingFmt(word, casing) : word).split(" ").join(separator);
7466
+ }).join(separator);
7467
+ return casing === "capital" ? name : this.casingFmt(name, casing);
7469
7468
  }
7469
+ pickWord(words) {
7470
+ if (words.length === 0) throw new Error("Cannot pick from an empty word list");
7471
+ return words[Math.floor(Math.random() * words.length)];
7472
+ }
7473
+ casingFmt(word, casing) {
7474
+ switch (casing) {
7475
+ case "upperCase": return word.toUpperCase();
7476
+ case "lowerCase": return word.toLowerCase();
7477
+ case "capital": return word.split(" ").map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join(" ");
7478
+ default: return word;
7479
+ }
7480
+ }
7481
+ };
7482
+ function createName(options) {
7483
+ return new Namelet(options).generate();
7470
7484
  }
7471
7485
  //#endregion
7472
7486
  export { createName };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "namelet",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Tiny, flexible name generator for JavaScript and TypeScript.",
5
5
  "keywords": [
6
6
  "name-generator",