namelet 0.1.0 → 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/README.md +83 -8
- package/dist/index.d.mts +12 -3
- package/dist/index.mjs +7484 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,14 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
Tiny, flexible name generator for JavaScript and TypeScript.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install namelet
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
- Configurable separators, length, and capitalization
|
|
11
|
-
- Seeded generation for repeatable results
|
|
12
|
-
- TypeScript support
|
|
13
|
-
- Minimal bundle size
|
|
11
|
+
## Usage
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
```ts
|
|
14
|
+
import { createName } from "namelet";
|
|
15
|
+
|
|
16
|
+
const name = createName({
|
|
17
|
+
wordLists: ["adjectives", "colors", "names"],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
console.log(name); // e.g. "brave-red-alice"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`createName` randomly selects one entry from each requested dictionary, keeps the
|
|
24
|
+
requested order, and joins the entries with a separator. By default, the separator
|
|
25
|
+
is `"-"` and the result is lowercase.
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
| Option | Type | Default | Description |
|
|
30
|
+
| ----------- | ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `wordLists` | `WordLists[]` | Required | Dictionaries to select from, in order. |
|
|
32
|
+
| `separator` | `string` | `"-"` | Text between entries and in place of spaces within an entry. Use `""` to join without a separator. |
|
|
33
|
+
| `casing` | `Casing` | `"lowerCase"` | `"lowerCase"`, `"upperCase"`, or `"capital"`. |
|
|
34
|
+
|
|
35
|
+
Available dictionaries: `"names"`, `"adjectives"`, `"cities"`, `"colors"`, and
|
|
36
|
+
`"starWars"`.
|
|
37
|
+
|
|
38
|
+
Repeat a dictionary to select more than one entry from it:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
createName({
|
|
42
|
+
wordLists: ["names", "names"],
|
|
43
|
+
separator: "_",
|
|
44
|
+
casing: "upperCase",
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each selection is independent, so repeated entries are possible. An empty
|
|
49
|
+
`wordLists` array returns an empty string. Entries can contain multiple words, so
|
|
50
|
+
the number of visible words can exceed the number of requested dictionaries.
|
|
51
|
+
|
|
52
|
+
## Casing
|
|
53
|
+
|
|
54
|
+
For an entry such as `"Anakin Skywalker"`, the default separator produces:
|
|
55
|
+
|
|
56
|
+
| Casing | Result |
|
|
57
|
+
| ------------- | -------------------- |
|
|
58
|
+
| `"lowerCase"` | `"anakin-skywalker"` |
|
|
59
|
+
| `"upperCase"` | `"ANAKIN-SKYWALKER"` |
|
|
60
|
+
| `"capital"` | `"Anakin-Skywalker"` |
|
|
61
|
+
|
|
62
|
+
`"capital"` uppercases the first character of each space-separated word and
|
|
63
|
+
lowercases the rest. For example, `"McDonald"` becomes `"Mcdonald"`. Capitalization
|
|
64
|
+
happens before joining, so `separator: ""` produces `"AnakinSkywalker"` for that
|
|
65
|
+
entry. Punctuation within words is preserved.
|
|
66
|
+
|
|
67
|
+
`"lowerCase"` and `"upperCase"` apply to the complete result, including any letters
|
|
68
|
+
in the separator. `"capital"` preserves the separator as supplied.
|
|
69
|
+
|
|
70
|
+
## TypeScript
|
|
71
|
+
|
|
72
|
+
The package includes TypeScript declarations and exports its option types:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { createName } from "namelet";
|
|
76
|
+
import type { Casing, NameOpts, WordLists } from "namelet";
|
|
77
|
+
|
|
78
|
+
const wordLists: WordLists[] = ["adjectives", "names"];
|
|
79
|
+
const casing: Casing = "capital";
|
|
80
|
+
const options: NameOpts = { wordLists, casing, separator: "_" };
|
|
81
|
+
|
|
82
|
+
const name: string = createName(options);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This package uses ES modules. Generation uses `Math.random()`; custom dictionaries
|
|
86
|
+
and seeded generation are not currently supported.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
|
|
1
|
+
//#region src/utils/types.d.ts
|
|
2
|
+
type Casing = "lowerCase" | "upperCase" | "capital";
|
|
3
|
+
type WordLists = "names" | "adjectives" | "cities" | "colors" | "starWars";
|
|
4
|
+
interface NameOpts {
|
|
5
|
+
wordLists: WordLists[];
|
|
6
|
+
separator?: string;
|
|
7
|
+
casing?: Casing;
|
|
8
|
+
}
|
|
3
9
|
//#endregion
|
|
4
|
-
|
|
10
|
+
//#region src/create-name.d.ts
|
|
11
|
+
declare function createName(options: NameOpts): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { type Casing, type NameOpts, type WordLists, createName };
|