human-ids 1.0.12 → 1.0.13
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/CHANGELOG.md +4 -0
- package/README.md +4 -0
- package/index.d.ts +1 -0
- package/index.js +10 -0
- package/package.json +1 -1
- package/tests/index.test.js +1 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@ const settings = {
|
|
|
55
55
|
adjective: true,
|
|
56
56
|
color: true,
|
|
57
57
|
noun: true,
|
|
58
|
+
randomOrder: false,
|
|
59
|
+
separator: '-',
|
|
60
|
+
asObject: false,
|
|
58
61
|
number: {
|
|
59
62
|
min: 0,
|
|
60
63
|
max: 999,
|
|
@@ -76,6 +79,7 @@ The settings object allows you to customize the ID generation process. The avail
|
|
|
76
79
|
noun: Set to true to include a noun in the ID (default: false).
|
|
77
80
|
randomOrder: Set to true to include a random order in the ID segments (default: false).
|
|
78
81
|
separator: Set to true to change a separator in the ID
|
|
82
|
+
asObject: Set to true to return an object with the words
|
|
79
83
|
number: An object that configures the number part of the ID:
|
|
80
84
|
min: The minimum value of the number (default: 0).
|
|
81
85
|
max: The maximum value of the number (default: 999).
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const defaultSettings = {
|
|
|
7
7
|
noun: true,
|
|
8
8
|
randomOrder: false,
|
|
9
9
|
separator: '-',
|
|
10
|
+
asObject: false,
|
|
10
11
|
number: {
|
|
11
12
|
min: 0,
|
|
12
13
|
max: 999,
|
|
@@ -81,6 +82,15 @@ function generateId(userSettings = {}) {
|
|
|
81
82
|
parts.sort(() => Math.random() - 0.5);
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
if (settings.asObject) {
|
|
86
|
+
const object = {};
|
|
87
|
+
const keys = ['adjective', 'color', 'noun', 'number'];
|
|
88
|
+
parts.forEach((part, index) => {
|
|
89
|
+
object[keys[index]] = part;
|
|
90
|
+
});
|
|
91
|
+
return object;
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
return parts.join(`${settings.separator}`);
|
|
85
95
|
}
|
|
86
96
|
|
package/package.json
CHANGED