stringzy 4.0.0 → 4.1.0

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.
Files changed (71) hide show
  1. package/README.md +445 -34
  2. package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
  3. package/dist/analyzing/checkMultiplePatterns.js +63 -0
  4. package/dist/analyzing/checkSubsequence.d.ts +14 -0
  5. package/dist/analyzing/checkSubsequence.js +33 -0
  6. package/dist/analyzing/contentWordCount.d.ts +11 -0
  7. package/dist/analyzing/contentWordCount.js +23 -0
  8. package/dist/analyzing/functionWordCount.d.ts +11 -0
  9. package/dist/analyzing/functionWordCount.js +33 -0
  10. package/dist/analyzing/index.d.ts +11 -0
  11. package/dist/analyzing/index.js +18 -2
  12. package/dist/analyzing/patternCount.d.ts +6 -5
  13. package/dist/analyzing/patternCount.js +19 -17
  14. package/dist/analyzing/stringRotation.d.ts +29 -0
  15. package/dist/analyzing/stringRotation.js +44 -0
  16. package/dist/index.d.ts +13 -0
  17. package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
  18. package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
  19. package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
  20. package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
  21. package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
  22. package/dist/tests/analyzing/contentWordCount.test.js +20 -0
  23. package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
  24. package/dist/tests/analyzing/functionWordCount.test.js +20 -0
  25. package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
  26. package/dist/tests/analyzing/stringRotation.test.js +42 -0
  27. package/dist/tests/transformations/reverseString.test.d.ts +1 -0
  28. package/dist/tests/transformations/reverseString.test.js +41 -0
  29. package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
  30. package/dist/tests/transformations/stringCombinations.test.js +41 -0
  31. package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
  32. package/dist/tests/transformations/stringPermutations.test.js +40 -0
  33. package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
  34. package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
  35. package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
  36. package/dist/tests/validations/isAlphabetic.test.js +32 -0
  37. package/dist/tests/validations/isAnagram.test.d.ts +1 -0
  38. package/dist/tests/validations/isAnagram.test.js +44 -0
  39. package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
  40. package/dist/tests/validations/isLowerCase.test.js +50 -0
  41. package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
  42. package/dist/tests/validations/isMacAddress.test.js +72 -0
  43. package/dist/tests/validations/isPanagram.test.d.ts +1 -0
  44. package/dist/tests/validations/isPanagram.test.js +39 -0
  45. package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
  46. package/dist/tests/validations/isUpperCase.test.js +50 -0
  47. package/dist/transformations/index.d.ts +9 -0
  48. package/dist/transformations/index.js +14 -2
  49. package/dist/transformations/reverseWordsInString .d.ts +9 -0
  50. package/dist/transformations/reverseWordsInString .js +49 -0
  51. package/dist/transformations/stringCombinations.d.ts +28 -0
  52. package/dist/transformations/stringCombinations.js +44 -0
  53. package/dist/transformations/stringPermutations.d.ts +31 -0
  54. package/dist/transformations/stringPermutations.js +53 -0
  55. package/dist/validations/index.d.ts +21 -0
  56. package/dist/validations/index.js +30 -2
  57. package/dist/validations/isAlphaNumeric.d.ts +11 -0
  58. package/dist/validations/isAlphaNumeric.js +22 -0
  59. package/dist/validations/isAlphabetic.d.ts +9 -0
  60. package/dist/validations/isAlphabetic.js +21 -0
  61. package/dist/validations/isAnagram.d.ts +13 -0
  62. package/dist/validations/isAnagram.js +23 -0
  63. package/dist/validations/isLowerCase.d.ts +12 -0
  64. package/dist/validations/isLowerCase.js +32 -0
  65. package/dist/validations/isMacAddress.d.ts +27 -0
  66. package/dist/validations/isMacAddress.js +43 -0
  67. package/dist/validations/isPanagram.d.ts +20 -0
  68. package/dist/validations/isPanagram.js +35 -0
  69. package/dist/validations/isUpperCase.d.ts +12 -0
  70. package/dist/validations/isUpperCase.js +32 -0
  71. package/package.json +3 -3
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  <div align="center">
2
2
 
3
-
4
- ![Stringzy banner](./assets/stringzy-banner2.jpg)
3
+ ![Stringzy banner](./assets/stringzy-banner2.jpg)
5
4
 
6
5
  ![NPM Version](https://img.shields.io/npm/v/stringzy)
7
6
  ![Typescript](https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white)
@@ -80,6 +79,9 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
80
79
  - [deburr](#deburr) – Removes accents and diacritical marks from a string
81
80
  - [splitChunks](#splitchunks) - Breaks a string down into chunks of specified length.
82
81
  - [numberToText](#numbertotext) - Converts a number to its text representation in specified language
82
+ - [reverseWordsInString](#reversewordsinstring) - Reverses the order of words in a given string
83
+ - [stringPermutations](#stringpermutations) - Generates all unique permutations of a given string.
84
+ - [stringCombinations](#stringcombinations) - Generates all unique combinations of a given string.
83
85
 
84
86
  ### Validations
85
87
 
@@ -93,19 +95,29 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
93
95
  - [isHexColor](#ishexcolor) - Checks if the input string is a valid hex color
94
96
  - [isPalindrome](#ispalindrome) - Checks if the input string is a palindrome (ignores case, spaces, and punctuation)
95
97
  - [isCoordinates](#iscoordinates) - Checks if given latitude and longitude are valid coordinates
98
+ - [isLowerCase](#islowercase) - Checks if given string only has lower case characters.
99
+ - [isUpperCase](#isuppercase) - Checks if given string only has upper case characters.
100
+ - [isAlphabetic](#isalphabetic) - Checks if input string contains only Alphabets (case insensitive)
101
+ - [isAlphaNumeric](#isalphanumeric) - Checks if input string contains only Alphabets and Digits (case insensitive)
102
+ - [isAnagram](#isanagram)- Checks if both strings are anagrams of each other. (ignores case and punctuations)
103
+ - [isMacAddress](#ismacaddress)- Checks if a given string is a valid MAC address.
104
+ - [isPanagram](#ispanagram)- Checks if a given string is a pangram (contains every letter of the English alphabet at least once).
96
105
 
97
106
  ### Analysis
98
107
 
99
108
  - [wordCount](#wordcount) - Counts the number of words in a string
109
+ - [contentWordCount](#contentwordcount)- Counts the number of content words (nouns, verbs, adjectives, adverbs, etc.) in a string.
110
+ - [functionWordCount](#functionwordcount)- Counts the number of function words (prepositions, pronouns, conjunctions, articles, etc.) in a string.
100
111
  - [readingDuration](#readingduration) - Calculates the reading duration of a given string
101
112
  - [characterCount](#charactercount) - Counts the number of characters in a string
102
113
  - [characterFrequency](#characterfrequency) - Analyzes character frequency in a string
103
114
  - [stringSimilarity](#stringsimilarity) - Calculates the percentage similarity between two strings
104
115
  - [complexity](#complexity) - Analyzes string complexity including score, uniqueness, and length
105
116
  - [patternCount](#patterncount) - calculates the number of times a specific pattern occurs in a given text
106
- - [vowelConsonantCount](#vowelconsonantcount) - Counts the number of vowels and consonants in a given string
107
-
108
-
117
+ - [vowelConsonantCount](#vowelconsonantcount) - Counts the number of vowels and consonants in a given string
118
+ - [checkMultiplePatterns](#checkmultiplepatterns) - Finds occurrences of multiple patterns within a given text using Rabin–Karp algorithm (case sensitive)
119
+ - [checkSubsequence](#checksubsequence) - Checks whether the second string is a subsequence of the first string (case sensitive)
120
+ - [stringRotation](#stringrotation) - Checks if one string is a rotation of another (case sensitive).
109
121
  ### Formatting
110
122
 
111
123
  - [capitalize](#capitalize) - Capitalizes the first letter of each word
@@ -413,7 +425,7 @@ maskSegment('token');
413
425
  | maskEnd | number | `text.length` | The end index (exclusive) of the segment to mask |
414
426
  | maskChar | string | `'*'` | The character to use for masking (must be one character) |
415
427
 
416
- #### <a id="deburr"></a>deburr(text)
428
+ #### <a id="deburr"></a>`deburr(text)`
417
429
 
418
430
  Removes accents and diacritics from letters in a string (e.g. déjà vu → deja vu).
419
431
 
@@ -459,7 +471,9 @@ splitChunks('helloworld');
459
471
  | chunkSize | number | `1` | The size of each chunk in which the string is to be split |
460
472
 
461
473
  ---
474
+
462
475
  #### <a id="numbertotext"></a>`numberToText(num, lang)`
476
+
463
477
  Converts a number to its text representation in the specified language.
464
478
 
465
479
  ```javascript
@@ -469,13 +483,93 @@ numberToText(12345, 'en'); // Returns: 'twelve thousand three hundred forty-five
469
483
  numberToText(12345, 'pl'); // Returns: 'dwanaście tysięcy trzysta czterdzieści pięć'
470
484
  ```
471
485
 
472
- | Parameter | Type | Default | Description |
473
- |-----------|--------|---------|-------------|
474
- | num | number | required | The number to convert to text |
475
- | lang | string | 'en' | The language code for the text representation (e.g., 'en' for English, 'pl' for Polish) |
486
+ | Parameter | Type | Default | Description |
487
+ | --------- | ------ | -------- | --------------------------------------------------------------------------------------- |
488
+ | num | number | required | The number to convert to text |
489
+ | lang | string | 'en' | The language code for the text representation (e.g., 'en' for English, 'pl' for Polish) |
476
490
 
477
491
  Available languages: en (English), pl (Polish).
478
492
 
493
+ #### <a id="reversewordsinstring"></a>`reverseWordsInString(str)`
494
+ Reverses the order of words in a string and reverses the position of surrounding whitespace (leading becomes trailing and vice-versa).
495
+ Reverses the order of words in a string while preserving the exact original spacing between each word.
496
+ ```javascript
497
+ import { reverseWordsInString } from 'stringzy';
498
+
499
+ reverseWordsInString('Hello world from stringzy');
500
+ // Returns: 'stringzy from world Hello'
501
+
502
+ // Note how the double and triple spaces are preserved:
503
+ reverseWordsInString(' leading spaces and trailing ');
504
+ // Returns: ' trailing and spaces leading '
505
+
506
+ reverseWordsInString('single-word');
507
+ // Returns: 'single-word'
508
+ ```
509
+ | Parameter | Type | Default | Description |
510
+ | --------- | ------ | -------- | --------------------------- |
511
+ | str | string | required | The input string to reverse |
512
+
513
+ #### <a id="stringpermutations"></a>`stringPermutations(str)`
514
+
515
+ Generates all unique permutations of a given string.
516
+ Repeated characters are handled by ensuring only unique permutations are included in the output array.
517
+ The order of permutations is not guaranteed.
518
+
519
+ ```javascript
520
+ stringPermutations('ab');
521
+ // ['ab', 'ba']
522
+
523
+ stringPermutations('abc');
524
+ // ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
525
+
526
+ stringPermutations('aab');
527
+ // ['aab', 'aba', 'baa']
528
+
529
+ stringPermutations('');
530
+ // ['']
531
+
532
+ stringPermutations('a');
533
+ // ['a']
534
+
535
+ stringPermutations('a1!');
536
+ // ['a1!', 'a!1', '1a!', '1!a', '!a1', '!1a']
537
+ ```
538
+
539
+ | Parameter | Type | Default | Description |
540
+ | --------- | ------ | -------- | ----------------------------------------------------- |
541
+ | str | string | required | The input string to generate all unique permutations. |
542
+
543
+ #### <a id="stringcombinations"></a>`stringCombinations(str)`
544
+
545
+ Generates all unique combinations (subsequences) of a given string, including the empty string.
546
+ Duplicate characters are handled by ensuring only unique combinations are returned.
547
+ The order of combinations in the output array is not guaranteed.
548
+
549
+ ```javascript
550
+ stringCombinations('ab');
551
+ // ["", "a", "b", "ab"]
552
+
553
+ stringCombinations('abc');
554
+ // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
555
+
556
+ stringCombinations('aab');
557
+ // ["", "a", "b", "aa", "ab", "aab"]
558
+
559
+ stringCombinations('');
560
+ // [""]
561
+
562
+ stringCombinations('A');
563
+ // ["", "A"]
564
+
565
+ stringCombinations('!@');
566
+ // ["", "!", "@", "!@"]
567
+ ```
568
+
569
+ | Parameter | Type | Default | Description |
570
+ | --------- | ------ | -------- | ------------------------------------------------------ |
571
+ | str | string | required | The input string to generate unique combinations from. |
572
+
479
573
 
480
574
  ### ✅ Validations
481
575
 
@@ -563,19 +657,18 @@ isSlug('hello_world'); // false (underscore not allowed)
563
657
  Checks if a file or URL has a valid extension for a given type
564
658
 
565
659
  ```javascript
566
- isType("photo.PNG", "image"); // true
567
- isType("https://example.com/logo.svg", "image"); // true
568
- isType({ name: "track.mp3" }, "audio"); // true
569
- isType("filewithoutextension", "image"); // false
570
- isType("document.zip", "document"); // false
571
- isType("video.mp4", "document"); // false
660
+ isType('photo.PNG', 'image'); // true
661
+ isType('https://example.com/logo.svg', 'image'); // true
662
+ isType({ name: 'track.mp3' }, 'audio'); // true
663
+ isType('filewithoutextension', 'image'); // false
664
+ isType('document.zip', 'document'); // false
665
+ isType('video.mp4', 'document'); // false
572
666
  ```
573
667
 
574
- | Parameter | Type | Default | Description |
575
- |-----------|------|---------|-------------|
576
- | input | string | required | The file name, URL string, or object with .name |
577
- | input | string | required | The file type category to validate (image, video, audio, document, archive) |
578
-
668
+ | Parameter | Type | Default | Description |
669
+ | --------- | ------ | -------- | --------------------------------------------------------------------------- |
670
+ | input | string | required | The file name, URL string, or object with .name |
671
+ | input | string | required | The file type category to validate (image, video, audio, document, archive) |
579
672
 
580
673
  #### <a id="isipv4"></a>`isIPv4(text)`
581
674
 
@@ -623,11 +716,11 @@ The check is case-insensitive and ignores spaces and punctuation.
623
716
  ```javascript
624
717
  import { isPalindrome } from 'stringzy';
625
718
 
626
- isPalindrome('racecar'); // true
627
- isPalindrome('A man, a plan, a canal: Panama'); // true
628
- isPalindrome('No lemon, no melon'); // true
629
- isPalindrome('hello'); // false
630
- isPalindrome('Was it a car or a cat I saw?'); // true
719
+ isPalindrome('racecar'); // true
720
+ isPalindrome('A man, a plan, a canal: Panama'); // true
721
+ isPalindrome('No lemon, no melon'); // true
722
+ isPalindrome('hello'); // false
723
+ isPalindrome('Was it a car or a cat I saw?'); // true
631
724
  ```
632
725
 
633
726
  | Parameter | Type | Default | Description |
@@ -646,12 +739,158 @@ isCoordinates(40.748817, -73.985428); // true
646
739
  isCoordinates(9999, -9999); // false
647
740
  ```
648
741
 
649
- | Parameter | Type | Default | Description |
650
- | --------- | ----------- | -------- | ----------------------------------------- |
651
- | latitude | number | required | Latitude to validate |
652
- | longitude | number | required | Longitude to validate |
742
+ | Parameter | Type | Default | Description |
743
+ | --------- | ------ | -------- | --------------------- |
744
+ | latitude | number | required | Latitude to validate |
745
+ | longitude | number | required | Longitude to validate |
746
+
747
+ #### <a id="islowercase"></a>`isLowerCase(str)`
748
+
749
+ Checks whether the given string contains only lowercase alphabetic characters.
750
+ Ignores digits, special characters, white spaces.
751
+
752
+ ```javascript
753
+ import { isLowerCase } from 'stringzy';
754
+
755
+ isLowerCase('hello'); // true
756
+ isLowerCase('hello123!'); // true
757
+ isLowerCase('Hello'); // false
758
+ isLowerCase('12345'); // false
759
+ ```
760
+
761
+ | Parameter | Type | Default | Description |
762
+ | --------- | ------ | -------- | ---------------------------------------------------------------------------- |
763
+ | str | string | required | The input string to validate as containing lowercase alphabetic letters |
764
+
765
+ #### <a id="isuppercase"></a>`isUpperCase(str)`
766
+
767
+ Checks whether the given string contains only uppercase alphabetic characters.
768
+ Ignores digits, special characters, white spaces.
769
+
770
+ ```javascript
771
+ import { isUpperCase } from 'stringzy';
772
+
773
+ isUpperCase('HELLO'); // true
774
+ isUpperCase('HELLO123!'); // true
775
+ isUpperCase('Hello'); // false
776
+ isUpperCase('12345'); // false
777
+ ```
778
+
779
+ | Parameter | Type | Default | Description |
780
+ | --------- | ------ | -------- | ---------------------------------------------------------------------------- |
781
+ | str | string | required | The input string to validate as containing uppercase alphabetic letters |
782
+
783
+ #### <a id="isalphabetic"></a>`isAlphabetic(text)`
784
+
785
+ Checks if a string contains only alphabetic characters (a-z, A-Z).
786
+ Throws an error if the input is not a string.
787
+
788
+ ```javascript
789
+ import { isAlphabetic } from 'stringzy';
790
+
791
+ isAlphabetic('hello'); // true
792
+ isAlphabetic('World'); // true
793
+ isAlphabetic('helloWORLD'); // true
794
+ isAlphabetic('abc123'); // false
795
+ isAlphabetic('hello!'); // false
796
+ isAlphabetic(''); // false
797
+ ```
798
+
799
+ | Parameter | Type | Default | Description |
800
+ | --------- | ------ | -------- | --------------------------------------------- |
801
+ | text | string | required | The input string to check for alphabetic only |
802
+
803
+ #### <a id="isalphanumeric"></a>`isAlphaNumeric(text)`
804
+
805
+ Checks if a string contains only alphanumeric characters (letters and digits).
806
+ Throws an error if the input is not a string.
807
+
808
+ ```javascript
809
+ import { isAlphaNumeric } from 'stringzy';
810
+
811
+ isAlphaNumeric('abc123'); // true
812
+ isAlphaNumeric('A1B2C3'); // true
813
+ isAlphaNumeric('123'); // true
814
+ isAlphaNumeric('hello'); // true
815
+ isAlphaNumeric('hello!'); // false
816
+ isAlphaNumeric('123 456'); // false
817
+ isAlphaNumeric(''); // false
818
+ ```
819
+
820
+ | Parameter | Type | Default | Description |
821
+ | --------- | ------ | -------- | ----------------------------------------------- |
822
+ | text | string | required | The input string to check for alphanumeric only |
823
+
824
+ #### <a id="isanagram"></a>`isAnagram(str1, str2)`
825
+
826
+ Checks whether two strings are anagrams of each other (contain the same characters in the same frequency, regardless of order).
827
+ - Comparison is case-insensitive.
828
+ - Spaces and punctuation are ignored.
829
+ - Throws an error if either input is not a string.
830
+
831
+ ```javascript
832
+ import { isAnagram } from 'stringzy';
833
+
834
+ isAnagram('listen', 'silent'); // true
835
+ isAnagram('Debit Card', 'Bad Credit'); // true
836
+ isAnagram('Astronomer', 'Moon starer'); // true
837
+ isAnagram('hello', 'world'); // false
838
+ isAnagram('a', 'b'); // false
839
+ isAnagram('', ''); // true
840
+ ```
841
+
842
+ | Parameter | Type | Default | Description |
843
+ | --------- | ------ | -------- | ---------------------------------------- |
844
+ | str1 | string | required | The first string to check as an anagram |
845
+ | str2 | string | required | The second string to check as an anagram |
846
+
847
+ #### <a id="ismacaddress"></a>`isMacAddress(str)`
848
+
849
+ Checks whether a given string is a valid **MAC address**.
850
+ - A valid MAC address consists of six pairs of hexadecimal digits (`0–9`, `A–F`, case-insensitive).
851
+ - Returns `true` if the string is a valid MAC address, otherwise `false`.
852
+ - Throws an error if input is not a string.
853
+
854
+ ```javascript
855
+ import { isMacAddress } from 'stringzy';
856
+
857
+ isMacAddress("00:1A:2B:3C:4D:5E"); // true
858
+ isMacAddress("00-1A-2B-3C-4D-5E"); // true
859
+ isMacAddress("aa:bb:cc:dd:ee:ff"); // true
860
+ isMacAddress("FF-FF-FF-FF-FF-FF"); // true
861
+
862
+ isMacAddress("00:1G:2B:3C:4D:5E"); // false (invalid hex digit)
863
+ isMacAddress("00:1A-2B:3C-4D:5E"); // false (mixed separators)
864
+ isMacAddress("001A:2B:3C:4D:5E"); // false (wrong group length)
865
+ isMacAddress("hello-world-mac"); // false (invalid format)
866
+ isMacAddress(""); // false (empty string)
867
+ ```
868
+
869
+ | Parameter | Type | Default | Description |
870
+ | --------- | ------ | -------- | --------------------------------------- |
871
+ | str | string | required | The string to validate as a MAC address |
872
+
873
+ #### <a id="ispanagram"></a>`isPangram(str)`
874
+
875
+ - Checks if a given string is a **pangram** (i.e., contains every letter of the English alphabet at least once).
876
+ - The check is **case-insensitive**, and non-alphabetic characters (numbers, punctuation, spaces) are ignored. An empty string is not considered a pangram.
877
+ - Throws an error if the input is not a string.
653
878
 
879
+ ```javascript
880
+ import { isPangram } from 'stringzy';
881
+
882
+ isPangram("The quick brown fox jumps over the lazy dog."); // true
883
+ isPangram("This is not a pangram."); // false
884
+ isPangram("Abcdefghijklmnopqrstuvwxyz"); // true
885
+ isPangram("AbCdEfGhIjKlMnOpQrStUvWxYz"); // true
886
+ isPangram("A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z"); // true
887
+ isPangram(""); // false
888
+ isPangram("Hello world"); // false
889
+ ```
654
890
 
891
+ | Parameter | Type | Default | Description |
892
+ | --------- | ------ | -------- | ----------------------------------------------------- |
893
+ | str | string | required | The input string to check for pangram characteristics |
655
894
  ---
656
895
 
657
896
  ### 📊 Analysis
@@ -741,8 +980,6 @@ stringSimilarity('flaw', 'lawn', 'Damerau-Levenshtein'); // Returns: 50
741
980
  | textB | string | required | The second text to compare. |
742
981
  | algorithm | string | 'Levenshtein' | The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. |
743
982
 
744
-
745
-
746
983
  #### <a id="complexity"></a>`complexity(text)`
747
984
 
748
985
  Analyzes the complexity of a string, returning an object with detailed metrics.
@@ -770,7 +1007,60 @@ complexity('');
770
1007
  - `uniqueness` (number): Measure of character uniqueness
771
1008
  - `length` (number): Length of the input string
772
1009
 
1010
+ feature/content-words
1011
+
1012
+ #### <a id="contentwordcount"></a>`contentWordCount(text)`
1013
+
1014
+ Counts the number of content words (nouns, verbs, adjectives, adverbs, etc.) in a string.
1015
+
1016
+ ```javascript
1017
+
1018
+ import { contentWordCount } from 'stringzy';
1019
+
1020
+ contentWordCount("Learning JavaScript improves coding skills!");
1021
+ // Returns: { count: 5 }
1022
+
1023
+ contentWordCount("The cat sleeps on the warm windowsill.");
1024
+ // Returns: { count: 5 }
773
1025
 
1026
+ contentWordCount("Wow! Such a beautiful day.");
1027
+ // Returns: { count: 4 }
1028
+ ```
1029
+
1030
+ | Parameter | Type | Default | Description |
1031
+ | --------- | ------ | -------- | -------------------------------------- |
1032
+ | text | string | required | The input string to analyze content words |
1033
+
1034
+ **Returns:** An object containing:
1035
+
1036
+ - `count` (number): Total number of content words in the string
1037
+
1038
+
1039
+ #### <a id="functionwordcount"></a>`functionWordCount(text)`
1040
+
1041
+ Counts the number of function words (prepositions, pronouns, conjunctions, articles, etc.) in a string.
1042
+
1043
+ ```javascript
1044
+
1045
+ import { functionWordCount } from 'stringzy';
1046
+
1047
+ functionWordCount("She and I are going to the park.");
1048
+ // Returns: { count: 7 }
1049
+
1050
+ functionWordCount("It is an example of proper grammar usage.");
1051
+ // Returns: { count: 8 }
1052
+
1053
+ functionWordCount("Can you see the stars tonight?");
1054
+ // Returns: { count: 5 }
1055
+ ```
1056
+
1057
+ | Parameter | Type | Default | Description |
1058
+ | --------- | ------ | -------- | -------------------------------------- |
1059
+ | text | string | required | The input string to analyze function words |
1060
+
1061
+ **Returns:** An object containing:
1062
+
1063
+ - `count` (number): Total number of function words in the string
774
1064
 
775
1065
  #### <a id="patterncount"></a>`patternCount(text, pattern)`
776
1066
 
@@ -795,7 +1085,7 @@ Counts the number of vowels and consonants in a given string.
795
1085
  This function is case-insensitive and ignores non-alphabetic characters.
796
1086
 
797
1087
  ```javascript
798
- vowelConsonantCount('hello');
1088
+ vowelConsonantCount('hello');
799
1089
  // { vowels: 2, consonants: 3 }
800
1090
 
801
1091
  vowelConsonantCount('stringzy');
@@ -809,6 +1099,95 @@ vowelConsonantCount('');
809
1099
  | --------- | ------ | -------- | -------------------------------------------------- |
810
1100
  | str | string | required | The input string to count vowels and consonants in |
811
1101
 
1102
+ feature/content-words
1103
+
1104
+ #### <a id="checkmultiplepatterns"></a>`checkMultiplePatterns(text, patterns)`
1105
+
1106
+ Finds occurrences of multiple patterns within a given text using the Rabin–Karp algorithm. <br>
1107
+ Accepts an array of patterns.<br>
1108
+ Returns all matches of each pattern along with starting indices.<br>
1109
+ Handles hash collisions by verifying actual substrings.<br>
1110
+ Pattern matching is case sensitive.
1111
+
1112
+ ```javascript
1113
+ checkMultiplePatterns('abracadabra', ['abra', 'cad']);
1114
+ // { abra: [0, 7], cad: [4] }
1115
+
1116
+ checkMultiplePatterns('aaaa', ['aa', 'aaa']);
1117
+ // { aa: [0, 1, 2], aaa: [0, 1] }
1118
+
1119
+ checkMultiplePatterns('hello world', ['xyz', '123']);
1120
+ // { xyz: [], 123: [] }
1121
+ ```
1122
+ | Parameter | Type | Default | Description |
1123
+ | --------- | --------- | -------- | ----------------------------------------------------------- |
1124
+ | text | string | required | The text to search within. |
1125
+ | patterns | string\[ ] | required | An array of patterns to search for (each must be a string). |
1126
+
1127
+ #### <a id="checksubsequence"></a>`checkSubsequence(str, sub)`
1128
+
1129
+ Checks whether a given string sub is a subsequence of another string str.
1130
+ A subsequence maintains the relative order of characters, but they do not need to be consecutive.
1131
+ Case-sensitive comparison is performed.
1132
+ Spaces and all characters are treated literally.
1133
+
1134
+ ```javascript
1135
+ isSubsequence('abcde', 'ace');
1136
+ // true → 'a', 'c', 'e' appear in order
1137
+
1138
+ isSubsequence('abracadabra', 'aaa');
1139
+ // true → multiple 'a's in correct order
1140
+
1141
+ isSubsequence('abcde', 'aec');
1142
+ // false → order is broken (e comes before c)
1143
+
1144
+ isSubsequence('anything', '');
1145
+ // true → empty subsequence is always valid
1146
+
1147
+ isSubsequence('AbC', 'AC');
1148
+ // true → exact case matches
1149
+
1150
+ isSubsequence('a b c', 'abc');
1151
+ // false → spaces count as characters
1152
+ ```
1153
+ | Parameter | Type | Default | Description |
1154
+ | --------- | ------ | -------- | ----------------------------------------------- |
1155
+ | str | string | required | The main string to check within. |
1156
+ | sub | string | required | The subsequence string to verify against `str`. |
1157
+
1158
+ #### <a id="stringrotation"></a>`checkStringRotations(str1, str2)`
1159
+ Checks whether a given string `str2` is a rotation of another string `str1`.
1160
+ Case-sensitive comparison is performed. Both strings must be of equal length to be considered rotations.
1161
+ Spaces and all characters are treated literally.
1162
+
1163
+ ```javascript
1164
+ isRotation('waterbottle', 'erbottlewat');
1165
+ // true → rotation at position 3
1166
+
1167
+ isRotation('abcde', 'cdeab');
1168
+ // true → rotation at position 2
1169
+
1170
+ isRotation('abc', 'abc');
1171
+ // true → no rotation, identical strings
1172
+
1173
+ isRotation('abc', 'cab');
1174
+ // true → rotation at position 2
1175
+
1176
+ isRotation('abc', 'bac');
1177
+ // false → not a valid rotation
1178
+
1179
+ isRotation('ArB', 'Bar');
1180
+ // false → case-sensitive mismatch
1181
+
1182
+ isRotation('abcd', 'abc');
1183
+ // false → lengths differ
1184
+ ```
1185
+
1186
+ | Parameter | Type | Default | Description |
1187
+ | --------- | ------ | -------- | --------------------------------------------------- |
1188
+ | str1 | string | required | The original string. |
1189
+ | str2 | string | required | The string to verify if it is a rotation of `str1`. |
1190
+
812
1191
  ---
813
1192
 
814
1193
  ### 🎨 Formatting
@@ -1158,13 +1537,45 @@ Contributions are welcome! Please read our [contribution guidelines](CONTRIBUTIN
1158
1537
  <td align="center">
1159
1538
  <a href="https://github.com/milendrakumarbaghel">
1160
1539
  <img src="https://avatars.githubusercontent.com/milendrakumarbaghel" width="100px;"
1161
- alt="Mariam Hasan" />
1540
+ alt="Milendra Kumar Baghel" />
1162
1541
  <br />
1163
1542
  <sub>
1164
1543
  <b>Milendra Kumar Baghel</b>
1165
1544
  </sub>
1166
1545
  </a>
1167
1546
  </td>
1547
+ <td align="center">
1548
+ <a href="https://github.com/Farkhanda-Dalal">
1549
+ <img src="https://avatars.githubusercontent.com/Farkhanda-Dalal" width="100px;"
1550
+ alt="Farkhanda Dalal" />
1551
+ <br />
1552
+ <sub>
1553
+ <b>Farkhanda Dalal</b>
1554
+ </sub>
1555
+ </a>
1556
+ </td>
1557
+ <td align="center">
1558
+ <a href="https://github.com/S">
1559
+ <img src="https://avatars.githubusercontent.com/satyasrisundarapalli" width="100px;"
1560
+ alt="Sundarapalli Lakshmi Satya Sri" />
1561
+ <br />
1562
+ <sub>
1563
+ <b>Sundarapalli Lakshmi Satya Sri</b>
1564
+ </sub>
1565
+ </a>
1566
+ </td>
1567
+ </tr>
1568
+ <tr>
1569
+ <td align="center">
1570
+ <a href="https://github.com/S">
1571
+ <img src="https://avatars.githubusercontent.com/itspavant" width="100px;"
1572
+ alt="T Pavan Teja" />
1573
+ <br />
1574
+ <sub>
1575
+ <b>T Pavan Teja</b>
1576
+ </sub>
1577
+ </a>
1578
+ </td>
1168
1579
  </tr>
1169
1580
  </tbody>
1170
1581
  </table>
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Finds occurrences of multiple patterns within a given text using Rabin–Karp algorithm.
3
+ *
4
+ * - Accepts an array of patterns.
5
+ * - Returns all matches of each pattern along with starting indices.
6
+ * - Handles hash collisions by verifying actual substrings.
7
+ * - Is case sensitive
8
+ *
9
+ * @param {string} text - The text to search within.
10
+ * @param {string[]} patterns - The array of patterns to search for.
11
+ * @returns {Record<string, number[]>} An object mapping each pattern to an array of match indices.
12
+ * @throws {TypeError} If input types are invalid.
13
+ */
14
+ export declare function checkMultiplePatterns(text: string, patterns: string[]): Record<string, number[]>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * Finds occurrences of multiple patterns within a given text using Rabin–Karp algorithm.
4
+ *
5
+ * - Accepts an array of patterns.
6
+ * - Returns all matches of each pattern along with starting indices.
7
+ * - Handles hash collisions by verifying actual substrings.
8
+ * - Is case sensitive
9
+ *
10
+ * @param {string} text - The text to search within.
11
+ * @param {string[]} patterns - The array of patterns to search for.
12
+ * @returns {Record<string, number[]>} An object mapping each pattern to an array of match indices.
13
+ * @throws {TypeError} If input types are invalid.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.checkMultiplePatterns = checkMultiplePatterns;
17
+ function checkMultiplePatterns(text, patterns) {
18
+ if (typeof text !== 'string') {
19
+ throw new TypeError('Text must be a string');
20
+ }
21
+ if (!Array.isArray(patterns) || !patterns.every(p => typeof p === 'string')) {
22
+ throw new TypeError('Patterns must be an array of strings');
23
+ }
24
+ const result = {};
25
+ if (text.length === 0 || patterns.length === 0) {
26
+ return result;
27
+ }
28
+ const prime = 101; // A prime base for hashing
29
+ const getHash = (str, m) => {
30
+ let h = 0;
31
+ for (let i = 0; i < m; i++) {
32
+ h = (h * 256 + str.charCodeAt(i)) % prime;
33
+ }
34
+ return h;
35
+ };
36
+ const recomputeHash = (oldHash, dropped, added, m) => {
37
+ let h = (oldHash - dropped.charCodeAt(0) * Math.pow(256, m - 1)) % prime;
38
+ h = (h * 256 + added.charCodeAt(0)) % prime;
39
+ if (h < 0)
40
+ h += prime;
41
+ return h;
42
+ };
43
+ for (const pattern of patterns) {
44
+ const m = pattern.length;
45
+ result[pattern] = [];
46
+ if (m === 0 || m > text.length)
47
+ continue;
48
+ const patternHash = getHash(pattern, m);
49
+ let windowHash = getHash(text, m);
50
+ for (let i = 0; i <= text.length - m; i++) {
51
+ if (patternHash === windowHash) {
52
+ // Verify to avoid collision false positives
53
+ if (text.slice(i, i + m) === pattern) {
54
+ result[pattern].push(i);
55
+ }
56
+ }
57
+ if (i < text.length - m) {
58
+ windowHash = recomputeHash(windowHash, text[i], text[i + m], m);
59
+ }
60
+ }
61
+ }
62
+ return result;
63
+ }