tiny-essentials 1.21.8 → 1.21.9

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.
@@ -351,17 +351,84 @@ const defaultTemplates = [
351
351
  */
352
352
  class UltraRandomMsgGen {
353
353
  /** @type {string[]} */
354
- static defaultWords = defaultWords;
354
+ static #defaultWords = defaultWords;
355
355
  /** @type {string[]} */
356
- static defaultEmojis = defaultEmojis;
356
+ static #defaultEmojis = defaultEmojis;
357
357
  /** @type {string[]} */
358
- static defaultNouns = defaultNouns;
358
+ static #defaultNouns = defaultNouns;
359
359
  /** @type {string[]} */
360
- static defaultVerbs = defaultVerbs;
360
+ static #defaultVerbs = defaultVerbs;
361
361
  /** @type {string[]} */
362
- static defaultAdjectives = defaultAdjectives;
362
+ static #defaultAdjectives = defaultAdjectives;
363
363
  /** @type {string[]} */
364
- static defaultTemplates = defaultTemplates;
364
+ static #defaultTemplates = defaultTemplates;
365
+ /**
366
+ * Utility to validate arrays before setting.
367
+ * @param {any} value
368
+ * @param {string} field
369
+ */
370
+ static #validateArray(value, field) {
371
+ if (!Array.isArray(value))
372
+ throw new TypeError(`${field} must be an array of strings`);
373
+ if (!value.every((v) => typeof v === 'string'))
374
+ throw new TypeError(`${field} must contain only strings`);
375
+ if (value.length === 0)
376
+ throw new Error(`${field} cannot be empty`);
377
+ }
378
+ /** @returns {string[]} */
379
+ static get defaultWords() {
380
+ return [...this.#defaultWords];
381
+ }
382
+ /** @param {string[]} value */
383
+ static set defaultWords(value) {
384
+ this.#validateArray(value, 'defaultWords');
385
+ this.#defaultWords = [...value];
386
+ }
387
+ /** @returns {string[]} */
388
+ static get defaultEmojis() {
389
+ return [...this.#defaultEmojis];
390
+ }
391
+ /** @param {string[]} value */
392
+ static set defaultEmojis(value) {
393
+ this.#validateArray(value, 'defaultEmojis');
394
+ this.#defaultEmojis = [...value];
395
+ }
396
+ /** @returns {string[]} */
397
+ static get defaultNouns() {
398
+ return [...this.#defaultNouns];
399
+ }
400
+ /** @param {string[]} value */
401
+ static set defaultNouns(value) {
402
+ this.#validateArray(value, 'defaultNouns');
403
+ this.#defaultNouns = [...value];
404
+ }
405
+ /** @returns {string[]} */
406
+ static get defaultVerbs() {
407
+ return [...this.#defaultVerbs];
408
+ }
409
+ /** @param {string[]} value */
410
+ static set defaultVerbs(value) {
411
+ this.#validateArray(value, 'defaultVerbs');
412
+ this.#defaultVerbs = [...value];
413
+ }
414
+ /** @returns {string[]} */
415
+ static get defaultAdjectives() {
416
+ return [...this.#defaultAdjectives];
417
+ }
418
+ /** @param {string[]} value */
419
+ static set defaultAdjectives(value) {
420
+ this.#validateArray(value, 'defaultAdjectives');
421
+ this.#defaultAdjectives = [...value];
422
+ }
423
+ /** @returns {string[]} */
424
+ static get defaultTemplates() {
425
+ return [...this.#defaultTemplates];
426
+ }
427
+ /** @param {string[]} value */
428
+ static set defaultTemplates(value) {
429
+ this.#validateArray(value, 'defaultTemplates');
430
+ this.#defaultTemplates = [...value];
431
+ }
365
432
  /** @type {MsgGenConfig} */
366
433
  config = {
367
434
  minLength: 10,
@@ -512,18 +579,18 @@ class UltraRandomMsgGen {
512
579
  throw new RangeError('config.line.emojiChance must be a number between 0 and 1');
513
580
  }
514
581
  }
515
- this.config.emojiSet = [...defaultEmojis];
516
- this.config.wordSet = [...defaultWords];
517
- this.config.grammar.templates = [...defaultTemplates];
518
- this.config.grammar.nouns = [...defaultNouns];
519
- this.config.grammar.verbs = [...defaultVerbs];
520
- this.config.grammar.adjectives = [...defaultAdjectives];
582
+ this.config.emojiSet = [...UltraRandomMsgGen.#defaultEmojis];
583
+ this.config.wordSet = [...UltraRandomMsgGen.#defaultWords];
584
+ this.config.grammar.templates = [...UltraRandomMsgGen.#defaultTemplates];
585
+ this.config.grammar.nouns = [...UltraRandomMsgGen.#defaultNouns];
586
+ this.config.grammar.verbs = [...UltraRandomMsgGen.#defaultVerbs];
587
+ this.config.grammar.adjectives = [...UltraRandomMsgGen.#defaultAdjectives];
521
588
  Object.assign(this.config, config);
522
589
  }
523
590
  /**
524
591
  * Merges new configuration values into the current instance.
525
592
  * @param {Object} newConfig - Object with one or more configuration overrides.
526
- * @returns {UltraRandomMsgGen} - The instance for chaining.
593
+ * @returns {this} - The instance for chaining.
527
594
  */
528
595
  configure(newConfig = {}) {
529
596
  Object.assign(this.config, newConfig);
@@ -532,7 +599,7 @@ class UltraRandomMsgGen {
532
599
  /**
533
600
  * Replaces the entire list of grammar templates.
534
601
  * @param {...string[]} templates - One or more arrays or strings containing sentence templates.
535
- * @returns {UltraRandomMsgGen} - The instance for chaining.
602
+ * @returns {this} - The instance for chaining.
536
603
  */
537
604
  setGrammarTemplates(...templates) {
538
605
  this.config.grammar.templates = templates.flat();
@@ -541,7 +608,7 @@ class UltraRandomMsgGen {
541
608
  /**
542
609
  * Adds new grammar templates to the existing list.
543
610
  * @param {...string[]} templates - One or more arrays or strings containing sentence templates.
544
- * @returns {UltraRandomMsgGen} - The instance for chaining.
611
+ * @returns {this} - The instance for chaining.
545
612
  */
546
613
  addGrammarTemplates(...templates) {
547
614
  this.config.grammar.templates.push(...templates.flat());
@@ -550,7 +617,7 @@ class UltraRandomMsgGen {
550
617
  /**
551
618
  * Replaces the list of noun words used in grammar templates.
552
619
  * @param {...string[]} nouns - One or more arrays or strings of nouns.
553
- * @returns {UltraRandomMsgGen} - The instance for chaining.
620
+ * @returns {this} - The instance for chaining.
554
621
  */
555
622
  setGrammarNouns(...nouns) {
556
623
  this.config.grammar.nouns = nouns.flat();
@@ -559,7 +626,7 @@ class UltraRandomMsgGen {
559
626
  /**
560
627
  * Adds noun words to the existing list used in grammar templates.
561
628
  * @param {...string[]} nouns - One or more arrays or strings of nouns.
562
- * @returns {UltraRandomMsgGen} - The instance for chaining.
629
+ * @returns {this} - The instance for chaining.
563
630
  */
564
631
  addGrammarNouns(...nouns) {
565
632
  this.config.grammar.nouns.push(...nouns.flat());
@@ -568,7 +635,7 @@ class UltraRandomMsgGen {
568
635
  /**
569
636
  * Replaces the list of verb words used in grammar templates.
570
637
  * @param {...string[]} verbs - One or more arrays or strings of verbs.
571
- * @returns {UltraRandomMsgGen} - The instance for chaining.
638
+ * @returns {this} - The instance for chaining.
572
639
  */
573
640
  setGrammarVerbs(...verbs) {
574
641
  this.config.grammar.verbs = verbs.flat();
@@ -577,7 +644,7 @@ class UltraRandomMsgGen {
577
644
  /**
578
645
  * Adds verb words to the existing list used in grammar templates.
579
646
  * @param {...string[]} verbs - One or more arrays or strings of verbs.
580
- * @returns {UltraRandomMsgGen} - The instance for chaining.
647
+ * @returns {this} - The instance for chaining.
581
648
  */
582
649
  addGrammarVerbs(...verbs) {
583
650
  this.config.grammar.verbs.push(...verbs.flat());
@@ -586,7 +653,7 @@ class UltraRandomMsgGen {
586
653
  /**
587
654
  * Replaces the list of adjective words used in grammar templates.
588
655
  * @param {...string[]} adjectives - One or more arrays or strings of adjectives.
589
- * @returns {UltraRandomMsgGen} - The instance for chaining.
656
+ * @returns {this} - The instance for chaining.
590
657
  */
591
658
  setGrammarAdjectives(...adjectives) {
592
659
  this.config.grammar.adjectives = adjectives.flat();
@@ -595,7 +662,7 @@ class UltraRandomMsgGen {
595
662
  /**
596
663
  * Adds adjective words to the existing list used in grammar templates.
597
664
  * @param {...string[]} adjectives - One or more arrays or strings of adjectives.
598
- * @returns {UltraRandomMsgGen} - The instance for chaining.
665
+ * @returns {this} - The instance for chaining.
599
666
  */
600
667
  addGrammarAdjectives(...adjectives) {
601
668
  this.config.grammar.adjectives.push(...adjectives.flat());
@@ -604,7 +671,7 @@ class UltraRandomMsgGen {
604
671
  /**
605
672
  * Removes specific grammar templates from the current list.
606
673
  * @param {...string[]} templates - One or more arrays or strings of templates to remove.
607
- * @returns {UltraRandomMsgGen} - The instance for chaining.
674
+ * @returns {this} - The instance for chaining.
608
675
  */
609
676
  removeGrammarTemplates(...templates) {
610
677
  const removeSet = new Set(templates.flat());
@@ -614,7 +681,7 @@ class UltraRandomMsgGen {
614
681
  /**
615
682
  * Removes specific noun words from the grammar noun list.
616
683
  * @param {...string[]} nouns - One or more arrays or strings of nouns to remove.
617
- * @returns {UltraRandomMsgGen} - The instance for chaining.
684
+ * @returns {this} - The instance for chaining.
618
685
  */
619
686
  removeGrammarNouns(...nouns) {
620
687
  const removeSet = new Set(nouns.flat());
@@ -624,7 +691,7 @@ class UltraRandomMsgGen {
624
691
  /**
625
692
  * Removes specific verb words from the grammar verb list.
626
693
  * @param {...string[]} verbs - One or more arrays or strings of verbs to remove.
627
- * @returns {UltraRandomMsgGen} - The instance for chaining.
694
+ * @returns {this} - The instance for chaining.
628
695
  */
629
696
  removeGrammarVerbs(...verbs) {
630
697
  const removeSet = new Set(verbs.flat());
@@ -634,7 +701,7 @@ class UltraRandomMsgGen {
634
701
  /**
635
702
  * Removes specific adjective words from the grammar adjective list.
636
703
  * @param {...string[]} adjectives - One or more arrays or strings of adjectives to remove.
637
- * @returns {UltraRandomMsgGen} - The instance for chaining.
704
+ * @returns {this} - The instance for chaining.
638
705
  */
639
706
  removeGrammarAdjectives(...adjectives) {
640
707
  const removeSet = new Set(adjectives.flat());
@@ -644,7 +711,7 @@ class UltraRandomMsgGen {
644
711
  /**
645
712
  * Replaces the entire word set used in readable/mixed modes.
646
713
  * @param {...string[]} words - One or more arrays or strings of words.
647
- * @returns {UltraRandomMsgGen} - The instance for chaining.
714
+ * @returns {this} - The instance for chaining.
648
715
  */
649
716
  setWords(...words) {
650
717
  this.config.wordSet = words.flat();
@@ -653,7 +720,7 @@ class UltraRandomMsgGen {
653
720
  /**
654
721
  * Adds new words to the word set used in readable/mixed modes.
655
722
  * @param {...string[]} words - One or more arrays or strings of words.
656
- * @returns {UltraRandomMsgGen} - The instance for chaining.
723
+ * @returns {this} - The instance for chaining.
657
724
  */
658
725
  addWords(...words) {
659
726
  this.config.wordSet.push(...words.flat());
@@ -662,7 +729,7 @@ class UltraRandomMsgGen {
662
729
  /**
663
730
  * Removes specific words from the word set.
664
731
  * @param {...string[]} words - Words to be removed.
665
- * @returns {UltraRandomMsgGen} - The instance for chaining.
732
+ * @returns {this} - The instance for chaining.
666
733
  */
667
734
  removeWords(...words) {
668
735
  const removeSet = new Set(words.flat());
@@ -672,7 +739,7 @@ class UltraRandomMsgGen {
672
739
  /**
673
740
  * Replaces the emoji set used in generated output.
674
741
  * @param {...string[]} emojis - One or more arrays or strings of emojis.
675
- * @returns {UltraRandomMsgGen} - The instance for chaining.
742
+ * @returns {this} - The instance for chaining.
676
743
  */
677
744
  setEmojis(...emojis) {
678
745
  this.config.emojiSet = emojis.flat();
@@ -681,7 +748,7 @@ class UltraRandomMsgGen {
681
748
  /**
682
749
  * Adds new emojis to the emoji set.
683
750
  * @param {...string[]} emojis - One or more arrays or strings of emojis.
684
- * @returns {UltraRandomMsgGen} - The instance for chaining.
751
+ * @returns {this} - The instance for chaining.
685
752
  */
686
753
  addEmojis(...emojis) {
687
754
  this.config.emojiSet.push(...emojis.flat());
@@ -690,7 +757,7 @@ class UltraRandomMsgGen {
690
757
  /**
691
758
  * Removes specific emojis from the emoji set.
692
759
  * @param {...string[]} emojis - Emojis to be removed.
693
- * @returns {UltraRandomMsgGen} - The instance for chaining.
760
+ * @returns {this} - The instance for chaining.
694
761
  */
695
762
  removeEmojis(...emojis) {
696
763
  const removeSet = new Set(emojis.flat());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.21.8",
3
+ "version": "1.21.9",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",