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 +1 -1
- package/dist/index.mjs +31 -17
- package/package.json +1 -1
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(
|
|
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
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
}
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
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 };
|