orc-me 1.2.2 → 1.2.6
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 +4 -6
- package/index.d.ts +8 -1
- package/index.js +37 -19
- package/package.json +2 -1
- package/test/index.test.js +27 -4
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
* 👹 NPM package to generate random orc names
|
|
18
18
|
* ✨ Get awesome orc names for your projects!
|
|
19
|
+
* 👹 An orc name is created by starting with a harsh consonant sound (like `gr`, `kr`, `th`, or `sh`), followed by a short, heavy vowel (`a`, `o`, or `u`), and usually ending with another hard consonant (`g`, `k`, `r`, or `z`). Sometimes an extra harsh sound is added at the end to make the name feel more brutal.
|
|
20
|
+
* ⭐ Updated the version using a custom `orc phoneme grammar` to avoid hardcoded array of names.
|
|
19
21
|
|
|
20
22
|
# Install [NPM](https://www.npmjs.com/package/orc-me) 📦
|
|
21
23
|
|
|
@@ -30,12 +32,8 @@
|
|
|
30
32
|
``` javascript
|
|
31
33
|
const orcMe = require('orc-me');
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const orcThreeNames = capitalizeFirstLetter(orcMe()) + ' ' + capitalizeFirstLetter(orcMe()) + ' ' + capitalizeFirstLetter(orcMe());
|
|
38
|
-
const orcTwoNames = capitalizeFirstLetter(orcMe()) + ' ' + capitalizeFirstLetter(orcMe());
|
|
35
|
+
const orcThreeNames = `${orcMe()} ${orcMe()} ${orcMe()}`;
|
|
36
|
+
const orcTwoNames = `${orcMe()} ${orcMe()}`;
|
|
39
37
|
|
|
40
38
|
console.log('Orc battle started! ⚔️');
|
|
41
39
|
console.log(orcThreeNames + ' ⚔️ ' + orcTwoNames);
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @version: v1.2.
|
|
2
|
+
* orc-me - 👹 Generate a random orc name
|
|
3
|
+
* @version: v1.2.6
|
|
4
4
|
* @link: https://github.com/tutyamxx/orc-me
|
|
5
5
|
* @license: MIT
|
|
6
6
|
**/
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
const pick = (src) => src?.[Math.random() * src.length | 0] ?? '';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generate a random Orc-style name.
|
|
12
|
+
*
|
|
13
|
+
* @returns A randomly generated orc name as a string
|
|
14
|
+
*/
|
|
15
|
+
const orcMe = () => {
|
|
16
|
+
// --| Onset: single or double harsh consonants
|
|
17
|
+
const onset = Math.random() < 0.5
|
|
18
|
+
? pick('gkrzbdh') // --| Single consonants
|
|
19
|
+
: pick(['gr', 'kr', 'th', 'sh', 'br', 'dr', 'gl', 'gh']);
|
|
20
|
+
|
|
21
|
+
// --| Vowels: single or diphthong for variety
|
|
22
|
+
const vowel = pick(['a', 'o', 'u', 'aa', 'oo', 'au']);
|
|
23
|
+
|
|
24
|
+
// --| Coda: optional, mostly harsh consonants or clusters
|
|
25
|
+
const coda = Math.random() < 0.7
|
|
26
|
+
? pick(['g', 'k', 'r', 'z', 'sh', 'rg', 'kk', 'zz', 'th'])
|
|
27
|
+
: '';
|
|
28
|
+
|
|
29
|
+
// --| Extra ending letter sometimes
|
|
30
|
+
const extra = Math.random() < 0.4
|
|
31
|
+
? pick('gkrz')
|
|
32
|
+
: '';
|
|
33
|
+
|
|
34
|
+
// --| Optional second syllable sometimes to make longer names
|
|
35
|
+
const secondSyllable = Math.random() < 0.3
|
|
36
|
+
? pick(['', '', 'g', 'k', 'r', 'z', 'sh']) + pick(['a', 'o', 'u'])
|
|
37
|
+
: '';
|
|
38
|
+
|
|
39
|
+
return `${onset}${vowel}${coda}${extra}${secondSyllable}`?.replace?.(/^./, c => c.toUpperCase()) ?? '';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = orcMe;
|
package/package.json
CHANGED
package/test/index.test.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
const orcMe = require('../index.js');
|
|
2
2
|
|
|
3
|
-
test('Check if it returns a random Orc name with
|
|
4
|
-
const expectedString = expect.stringMatching(/^[a-z]{
|
|
3
|
+
test('Check if it returns a random Orc name with valid characters and length', () => {
|
|
4
|
+
const expectedString = expect.stringMatching(/^[A-Z][a-z]{1,6}$/);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const name = orcMe();
|
|
7
|
+
|
|
8
|
+
expect(name).toEqual(expectedString);
|
|
9
|
+
expect(name).not.toBe('');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('Check that multiple calls return strings', () => {
|
|
13
|
+
for (let i = 0; i < 10; i++) {
|
|
14
|
+
expect(typeof orcMe()).toBe('string');
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Check that generated names are not all identical', () => {
|
|
19
|
+
const names = new Set(Array.from({ length: 10 }, () => orcMe()));
|
|
20
|
+
expect(names.size).toBeGreaterThan(1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('Check that the first character is uppercase', () => {
|
|
24
|
+
const name = orcMe();
|
|
25
|
+
expect(name[0]).toMatch(/[A-Z]/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('Check that the name contains at least one vowel', () => {
|
|
29
|
+
const name = orcMe().toLowerCase();
|
|
30
|
+
expect(name).toMatch(/[aou]/);
|
|
8
31
|
});
|