stringzy 2.0.1 → 2.2.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.
package/README.md CHANGED
@@ -1,12 +1,25 @@
1
- # stringzy
1
+
2
+ <div align="center">
3
+
4
+
5
+ ![Stringzy banner](./assets/stringzy-banner2.jpg)
6
+
2
7
 
3
8
  ![NPM Version](https://img.shields.io/npm/v/stringzy)
4
9
  ![Downloads](https://img.shields.io/npm/dt/stringzy)
5
10
  ![License](https://img.shields.io/npm/l/stringzy)
6
11
  ![Bundle Size](https://img.shields.io/bundlephobia/min/stringzy)
12
+ [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)
13
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
14
 
8
15
  **A lightweight, zero-dependency NPM Package for elegant string manipulations. It provides a comprehensive range of text utilities for JavaScript and Node.js applications including transformations, validations, analysis, and formatting.**
9
16
 
17
+ [Checkout our Contributors!](#contri)
18
+
19
+
20
+ </div>
21
+
22
+
10
23
  ## ✨ Features
11
24
 
12
25
  - 💪 **Powerful** - Transform, validate, analyze, and format strings with minimal code
@@ -54,6 +67,9 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
54
67
  - [toSlug](#toslug) - Converts a string to a URL-friendly slug
55
68
  - [capitalizeWords](#capitalizewords) - Capitalizes the first letter of each word
56
69
  - [removeSpecialChars](#removespecialchars) - Removes special characters from a string
70
+ - [removeWords](#removewords) - Removes specified words from a string
71
+ - [removeDuplicates](#removeduplicates) - Removes specified words from a string
72
+ - [initials](#initials) - Extracts initials from a text string
57
73
  - [camelCase](#camelcase) - Converts the given string to Camel Case
58
74
  - [pascaslCase](#pascalcase) - Converts the given string to Pascal Case
59
75
  - [snakeCase](#snakecase) - Converts the given string to Snake Case
@@ -64,6 +80,7 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
64
80
  ### Validations
65
81
  - [isURL](#isurl) - Checks if a string is a valid URL
66
82
  - [isEmail](#isemail) - Checks if a string is a valid email address
83
+ - [isDate](#isdate) - Checks if a string is a valid date
67
84
  - [isEmpty](#isempty) - Checks if a string is empty or contains only whitespace
68
85
 
69
86
  ### Analysis
@@ -169,6 +186,77 @@ removeSpecialChars('Phone: (123) 456-7890', '-');
169
186
  | text | string | required | The input string to process |
170
187
  | replacement | string | '' | String to replace special characters with |
171
188
 
189
+ #### <a id="removewords"></a>`removeWords(text, wordsToRemove)`
190
+
191
+ Removes specified words from a string
192
+
193
+ ```javascript
194
+ import { removeWords } from 'stringzy';
195
+
196
+ removeWords('Hello world this is a test', ['this', 'is']);
197
+ // Returns: 'Hello world a test'
198
+
199
+ removeWords('Remove The Quick BROWN fox', ['the', 'brown']);
200
+ // Returns: 'Remove Quick fox'
201
+
202
+ removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']);
203
+ // Returns: 'is awesome and rocks'
204
+ ```
205
+
206
+ | Parameter | Type | Default | Description |
207
+ |-----------|------|---------|-------------|
208
+ | text | string | required | The input string to process |
209
+ | wordsToRemove | string[] | required | Array of words to remove from the string |
210
+
211
+ #### <a id="removeduplicates"></a>`removeDuplicates(text)`
212
+
213
+ Removes duplicate case-sensitive words from a given text.
214
+
215
+ ```javascript
216
+ import { removeDuplicates } from 'stringzy';
217
+
218
+ removeDuplicates('Hello world this is a is a test');
219
+ // Returns: 'Hello world this is a test'
220
+
221
+ removeDuplicates('Remove me me me me or Me');
222
+ // Returns: 'Remove me or Me''
223
+
224
+ removeDuplicates('JavaScript is not bad and not awesome');
225
+ // Returns: 'JavaScript is not bad and awesome'
226
+ ```
227
+
228
+ | Parameter | Type | Default | Description |
229
+ |-----------|------|---------|-------------|
230
+ | text | string | required | The input string to process |
231
+
232
+ #### <a id="initials"></a>`initials(text, limit)`
233
+
234
+ Extracts initials from a text string.
235
+
236
+ ```javascript
237
+ import { initials } from 'stringzy';
238
+
239
+ initials('John Doe');
240
+ // Returns: 'JD'
241
+
242
+ initials('Alice Bob Charlie', 2);
243
+ // Returns: 'AB'
244
+
245
+ initials('Hello World Test Case');
246
+ // Returns: 'HWTC'
247
+
248
+ initials('single');
249
+ // Returns: 's'
250
+
251
+ initials(' Multiple Spaces Between ');
252
+ // Returns: 'MSB'
253
+ ```
254
+
255
+ | Parameter | Type | Default | Description |
256
+ |-----------|------|---------|-------------|
257
+ | text | string | required | The input string to extract initials from |
258
+ | limit | number | undefined | Maximum number of initials to return (optional) |
259
+
172
260
  #### <a id="camelcase"></a>`camelCase(text)`
173
261
 
174
262
  Converts the given string to Camel Case.
@@ -294,6 +382,23 @@ isEmail('invalid-email'); // false
294
382
  |-----------|------|---------|-------------|
295
383
  | text | string | required | The input string to validate as email |
296
384
 
385
+ #### <a id="isdate"></a>`isDate(text)`
386
+
387
+ Checks if a string is a valid date.
388
+
389
+ ```javascript
390
+ import { isDate } from 'stringzy';
391
+
392
+ isDate('2023-12-25'); // true
393
+ isDate('12/25/2023'); // true
394
+ isDate('invalid-date'); // false
395
+ isDate('2023-13-45'); // false
396
+ ```
397
+
398
+ | Parameter | Type | Default | Description |
399
+ |-----------|------|---------|-------------|
400
+ | text | string | required | The input string to validate as date |
401
+
297
402
  #### <a id="isempty"></a>`isEmpty(text)`
298
403
 
299
404
  Checks if a string is empty or contains only whitespace.
@@ -541,6 +646,67 @@ Contributions are welcome! Please feel free to submit a Pull Request.
541
646
  4. Push to the branch (`git push origin feature/amazing-feature`)
542
647
  5. Open a Pull Request
543
648
 
649
+
650
+ ## <a id="contri"></a>`Contributors`
651
+
652
+ <table>
653
+ <tbody>
654
+ <tr>
655
+ <td align="center">
656
+ <a href="https://github.com/Samarth2190">
657
+ <img src="https://avatars.githubusercontent.com/Samarth2190" width="100px;"
658
+ alt="Samarth Ruia" />
659
+ <br />
660
+ <sub>
661
+ <b>Samarth Ruia</b>
662
+ </sub>
663
+ </a>
664
+ </td>
665
+ <td align="center">
666
+ <a href="https://github.com/JohnCervantes">
667
+ <img src="https://avatars.githubusercontent.com/JohnCervantes" width="100px;"
668
+ alt="John Cervantes" />
669
+ <br />
670
+ <sub>
671
+ <b>John Cervantes</b>
672
+ </sub>
673
+ </a>
674
+ </td>
675
+ <td align="center">
676
+ <a href="https://github.com/thehardiik">
677
+ <img src="https://avatars.githubusercontent.com/thehardiik" width="100px;"
678
+ alt="Hardik Srivastav" />
679
+ <br />
680
+ <sub>
681
+ <b>Hardik Srivastav</b>
682
+ </sub>
683
+ </a>
684
+ </td>
685
+ <td align="center">
686
+ <a href="https://github.com/ahmedsemih">
687
+ <img src="https://avatars.githubusercontent.com/ahmedsemih" width="100px;"
688
+ alt="Ahmed Semih Erkan" />
689
+ <br />
690
+ <sub>
691
+ <b>Ahmed Semih Erkan</b>
692
+ </sub>
693
+ </a>
694
+ </td>
695
+ <td align="center">
696
+ <a href="https://github.com/michaelvbend">
697
+ <img src="https://avatars.githubusercontent.com/michaelvbend" width="100px;"
698
+ alt="Michael van der Bend" />
699
+ <br />
700
+ <sub>
701
+ <b>Michael van der Bend</b>
702
+ </sub>
703
+ </a>
704
+ </td>
705
+ </tr>
706
+ </tbody>
707
+ </table>
708
+
709
+
544
710
  ## 📝 License
545
711
 
546
712
  This project is licensed under the MIT License - see the LICENSE file for details.
@@ -550,6 +716,8 @@ This project is licensed under the MIT License - see the LICENSE file for detail
550
716
  - Thank you to all contributors and users of this package!
551
717
  - Inspired by the need for comprehensive yet simple string manipulation utilities.
552
718
 
719
+ If you have contributed to this project and your image is not here, please let us know, and we'll be happy to add it!
720
+
553
721
  ---
554
722
 
555
- Made with ❤️ by Samarth Ruia
723
+ Made with ❤️ by Samarth Ruia
Binary file
package/changelog.txt CHANGED
@@ -2,6 +2,26 @@ CHANGELOG
2
2
 
3
3
  All notable changes to the `stringzy` package will be documented in this file.
4
4
 
5
+ =============================================================================
6
+ Version 2.1.0 - 2025-05-31
7
+ -----------------------------------------------------------------------------
8
+
9
+ ADDED:
10
+ - Added new utility functions:
11
+ - `removeDuplicates`: Removes duplicate words from a string
12
+ - Added the stringzy banner to the README
13
+
14
+ =============================================================================
15
+ Version 2.1.0 - 2025-05-31
16
+ -----------------------------------------------------------------------------
17
+
18
+ ADDED:
19
+ - Added new utility functions:
20
+ - `removeWords`:
21
+ - `isDate`: Validates if a string is a valid date
22
+ - Added contributors section in README
23
+ - Added new badges for open source and PRs
24
+
5
25
  =============================================================================
6
26
  Version 2.0.1 - 2025-05-23
7
27
  -----------------------------------------------------------------------------
package/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @module stringzy
9
9
  * @author Samarth Ruia
10
- * @version 2.0.0
10
+ * @version 2.2.0
11
11
  */
12
12
 
13
13
  import * as transformations from './transformations.js';
@@ -27,12 +27,16 @@ export const {
27
27
  kebabCase,
28
28
  titleCase,
29
29
  constantCase,
30
+ removeWords,
31
+ initials,
32
+ removeDuplicates
30
33
  } = transformations;
31
34
 
32
35
  export const {
33
36
  isURL,
34
37
  isEmail,
35
- isEmpty
38
+ isEmpty,
39
+ isDate,
36
40
  } = validations;
37
41
 
38
42
  export const {
@@ -64,4 +68,8 @@ export default {
64
68
  analyze: analysis,
65
69
  format: formatting,
66
70
 
67
- };
71
+ transform,
72
+ validate,
73
+ analyze,
74
+ format,
75
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stringzy",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -125,4 +125,66 @@ export function constantCase(text) {
125
125
  .toUpperCase()
126
126
  .replace(/_+/g, '_')
127
127
  .replace(/^_+|_+$/g, '');
128
- }
128
+ }
129
+
130
+ export function removeWords(str, wordsToRemove) {
131
+ if (str === null || str === undefined) {
132
+ throw new Error('Input string cannot be null or undefined');
133
+ }
134
+ if (typeof str !== 'string') {
135
+ throw new Error('First parameter must be a string');
136
+ }
137
+ if (wordsToRemove === null || wordsToRemove === undefined) {
138
+ throw new Error('Words to remove cannot be null or undefined');
139
+ }
140
+ if (typeof wordsToRemove !== 'string' && !Array.isArray(wordsToRemove)) {
141
+ throw new Error('Second parameter must be a string or an array of strings');
142
+ }
143
+ if (str === '') {
144
+ return '';
145
+ }
146
+ const wordsArray = Array.isArray(wordsToRemove) ? wordsToRemove : [wordsToRemove];
147
+ const regex = new RegExp(`\\b(${wordsArray.join('|')})\\b`, 'gi');
148
+ return str.replace(regex, '').replace(/\s+/g, ' ').trim();
149
+ }
150
+
151
+ export function initials(text, limit) {
152
+ if (typeof text !== "string") {
153
+ throw new Error("Input must be a string");
154
+ }
155
+
156
+ if (limit !== undefined && (typeof limit !== "number" || isNaN(limit))) {
157
+ throw new Error("Limit must be a valid number");
158
+ }
159
+
160
+ if (limit < 0) {
161
+ throw new Error("Limit must be a non-negative number");
162
+ }
163
+
164
+ const words = text
165
+ .trim()
166
+ .split(/\s+/)
167
+ .filter((word) => word.length > 0);
168
+
169
+ if (words.length === 0) return "";
170
+
171
+ const initialsArray = words
172
+ .map((word) => word.charAt(0))
173
+ .slice(0, limit ?? words.length);
174
+
175
+ return initialsArray.join("");
176
+ }
177
+
178
+ export function removeDuplicates(text) {
179
+ if (typeof text !== "string") {
180
+ throw new Error("Input must be a string");
181
+ }
182
+
183
+ const wordSet = new Set();
184
+
185
+ text.split(" ").forEach((word) => {
186
+ wordSet.add(word);
187
+ });
188
+
189
+ return Array.from(wordSet).join(" ");
190
+ }
package/validations.js CHANGED
@@ -16,4 +16,65 @@ export function isEmail(str) {
16
16
 
17
17
  export function isEmpty(str) {
18
18
  return str.trim().length === 0;
19
- }
19
+ }
20
+
21
+
22
+
23
+ export function isDate(input) {
24
+
25
+ //console.log("True")
26
+
27
+
28
+
29
+ if (typeof input !== "string") return false;
30
+
31
+ const formats = [
32
+ {
33
+ // Format: YYYY-MM-DD
34
+ regex: /^\d{4}-\d{2}-\d{2}$/,
35
+ split: (s) => s.split("-").map(Number),
36
+ order: ["Y", "M", "D"],
37
+ },
38
+ {
39
+ // Format: MM-DD-YYYY
40
+ regex: /^\d{2}-\d{2}-\d{4}$/,
41
+ split: (s) => s.split("-").map(Number),
42
+ order: ["M", "D", "Y"],
43
+ },
44
+ {
45
+ // Format: DD-MM-YYYY
46
+ regex: /^\d{2}-\d{2}-\d{4}$/,
47
+ split: (s) => s.split("-").map(Number),
48
+ order: ["D", "M", "Y"],
49
+ },
50
+ {
51
+ // Format: DD/MM/YYYY
52
+ regex: /^\d{2}\/\d{2}\/\d{4}$/,
53
+ split: (s) => s.split("/").map(Number),
54
+ order: ["D", "M", "Y"],
55
+ },
56
+ {
57
+ // Format: YYYY/MM/DD
58
+ regex: /^\d{4}\/\d{2}\/\d{2}$/,
59
+ split: (s) => s.split("/").map(Number),
60
+ order: ["Y", "M", "D"],
61
+ },
62
+ ];
63
+
64
+ for (const format of formats) {
65
+ if (format.regex.test(input)) {
66
+ const parts = format.split(input);
67
+ const dateParts = {};
68
+ format.order.forEach((key, i) => {
69
+ dateParts[key] = parts[i];
70
+ });
71
+
72
+ const { Y, M, D } = dateParts;
73
+ const date = new Date(Y, M - 1, D); // JS months are 0-indexed
74
+ return date.getFullYear() === Y && date.getMonth() === M -1 && date.getDate() === D;
75
+ }
76
+ }
77
+
78
+ return false;
79
+ }
80
+