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 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
- function capitalizeFirstLetter(string) {
34
- return string.charAt(0).toUpperCase() + string.slice(1);
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
@@ -1 +1,8 @@
1
- export default function (): string;
1
+ /**
2
+ * Generate a random Orc-style name.
3
+ *
4
+ * @returns A randomly generated orc name as a string
5
+ */
6
+ declare function orcName(): string;
7
+
8
+ export = orcName;
package/index.js CHANGED
@@ -1,24 +1,42 @@
1
1
  /**
2
- * orchish - 👹 Generate a random orc name
3
- * @version: v1.2.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 randomOrcnameStrings = [
9
- 'ach', 'adz', 'ak', 'ark', 'az', 'balg', 'bilg', 'blid', 'blig', 'blok', 'blot', 'bolg', 'bot', 'bug', 'burk', 'dokh', 'drik', 'driz', 'duf', 'flug', 'ga', 'gad', 'gag', 'gah',
10
- 'gak', 'gar', 'gat', 'gaz', 'ghag', 'ghak', 'git', 'glag', 'glak', 'glat', 'glig', 'gliz', 'glok', 'gnat', 'gog', 'grak', 'grat', 'guk', 'hig', 'irk', 'kak', 'khad', 'krig', 'lag',
11
- 'lak', 'lig', 'likk', 'loz', 'luk', 'mak', 'maz', 'miz', 'mub', 'nad', 'nag', 'naz', 'nig', 'nikk', 'nogg', 'nok', 'nukk', 'rag', 'rak', 'rat', 'rok', 'shrig', 'shuk', 'skrag', 'skug',
12
- 'slai', 'slig', 'slog', 'sna', 'snag', 'snark', 'snat', 'snig', 'snik', 'snit', 'sog', 'spik', 'stogg', 'tog', 'urf', 'vark', 'yad', 'yagg', 'yak', 'yark', 'yarp', 'yig', 'yip', 'zat',
13
- 'zib', 'zit', 'ziz', 'ag', 'aug', 'bad', 'bag', 'bakh', 'bash', 'baz', 'blag', 'brag', 'brog', 'bruz', 'dag', 'dakk', 'darg', 'dob', 'dog', 'drab', 'dug', 'dur', 'gash', 'ghaz', 'glakh',
14
- 'glaz', 'glob', 'glol', 'gluf', 'glur', 'gnarl', 'gnash', 'gnub', 'gob', 'gokh', 'gol', 'golk', 'gor', 'grakh', 'grash', 'grath', 'graz', 'grot', 'grub', 'grud', 'gud', 'gut', 'hag',
15
- 'hakk', 'hrat', 'hrog', 'hrug', 'khag', 'khar', 'krag', 'krud', 'lakh', 'lash', 'lob', 'lub', 'lud', 'luf', 'luk', 'molk', 'muk', 'muz', 'nar', 'ogg', 'olg', 'rag', 'rash', 'rogg', 'rorg',
16
- 'rot', 'rud', 'ruft', 'rug', 'rut', 'shad', 'shag', 'shak', 'shaz', 'shog', 'skar', 'skulg', 'slur', 'snar', 'snorl', 'snub', 'snurr', 'sod', 'stulg', 'thak', 'trog', 'ug', 'umsh', 'ung',
17
- 'uth', 'yakh', 'yash', 'yob', 'zahk', 'zog', 'argh', 'barsh', 'bog', 'burz', 'dof', 'drok', 'drub', 'drug', 'dub', 'dug', 'dul', 'dursh', 'dush', 'duz', 'faug', 'fug', 'ghakh', 'ghar', 'ghash',
18
- 'ghol', 'ghor', 'ghukk', 'ghul', 'glub', 'glud', 'glug', 'gluz', 'gom', 'grad', 'grash', 'grob', 'grogg', 'grok', 'grol', 'gru', 'gruf', 'gruk', 'grul', 'grum', 'grumf', 'grut', 'gruz', 'guhl',
19
- 'gulv', 'hai', 'hrung', 'hur', 'hurg', 'kai', 'klob', 'krod', 'kug', 'kulk', 'kur', 'lorg', 'lug', 'lukh', 'lum', 'lurz', 'lush', 'luz', 'makh', 'maug', 'molg', 'mud', 'mug', 'mul', 'murk', 'muzd',
20
- 'nakh', 'narg', 'obb', 'rolb', 'rukh', 'ruz', 'sharg', 'shruf', 'shud', 'shug', 'shur', 'shuz', 'slub', 'slud', 'slug', 'snad', 'snog', 'thrag', 'thulk', 'thurk', 'trug', 'ulg', 'ur', 'urd', 'urgh',
21
- 'urkh', 'uz', 'yug', 'yur', 'zud', 'zug', 'xug', 'grug'
22
- ];
23
-
24
- module.exports = () => randomOrcnameStrings[Math.floor(Math.random() * randomOrcnameStrings.length)];
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
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "orc-me",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "description": "Generate a random orc name",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "scripts": {
7
8
  "test": "jest --verbose"
8
9
  },
@@ -1,8 +1,31 @@
1
1
  const orcMe = require('../index.js');
2
2
 
3
- test('Check if it returns a random Orc name with a length between 2 and 5 chars', () => {
4
- const expectedString = expect.stringMatching(/^[a-z]{2,5}$/);
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
- expect(orcMe()).toEqual(expectedString);
7
- expect(orcMe()).not.toBe('');
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
  });