human-ids 1.0.11 → 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 +8 -0
- package/README.md +4 -0
- package/index.d.ts +1 -0
- package/index.js +12 -2
- package/package.json +1 -1
- package/tests/index.test.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [1.0.13] - 2023-07-10
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Added asObject setting to return an object with the words
|
|
11
|
+
## [1.0.12] - 2023-07-07
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fixed bug with undefined disctionaries
|
|
7
15
|
## [1.0.11] - 2023-07-07
|
|
8
16
|
|
|
9
17
|
### Fixed
|
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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const dictionaries = require('./dictionaries');
|
|
2
2
|
|
|
3
3
|
const defaultSettings = {
|
|
4
|
-
lang: '
|
|
4
|
+
lang: 'es',
|
|
5
5
|
adjective: true,
|
|
6
6
|
color: true,
|
|
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,
|
|
@@ -16,7 +17,7 @@ const defaultSettings = {
|
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
function generateId(userSettings = {}) {
|
|
19
|
-
const settings =
|
|
20
|
+
const settings = {...defaultSettings, ...userSettings};
|
|
20
21
|
const lang = dictionaries[settings.lang] ? settings.lang : dictionaries[settings.lang?.split('-')[0]] ? settings.lang?.split('-')[0] : 'en';
|
|
21
22
|
const useAdjective = settings.adjective || false;
|
|
22
23
|
const useColor = settings.color || false;
|
|
@@ -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
package/tests/index.test.js
CHANGED
|
@@ -2,7 +2,7 @@ const generateId = require('../index');
|
|
|
2
2
|
|
|
3
3
|
describe('generateId', () => {
|
|
4
4
|
test('should return a unique ID', () => {
|
|
5
|
-
const testLength =
|
|
5
|
+
const testLength = 1000;
|
|
6
6
|
const settings = {
|
|
7
7
|
lang: 'en',
|
|
8
8
|
adjective: true,
|
|
@@ -10,6 +10,7 @@ describe('generateId', () => {
|
|
|
10
10
|
noun: true,
|
|
11
11
|
randomOrder: true,
|
|
12
12
|
separator: '-',
|
|
13
|
+
asObject: false,
|
|
13
14
|
number: {
|
|
14
15
|
min: 0,
|
|
15
16
|
max: 9999,
|