stringzy 2.0.1 → 2.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.
package/README.md CHANGED
@@ -4,9 +4,13 @@
4
4
  ![Downloads](https://img.shields.io/npm/dt/stringzy)
5
5
  ![License](https://img.shields.io/npm/l/stringzy)
6
6
  ![Bundle Size](https://img.shields.io/bundlephobia/min/stringzy)
7
+ [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)
8
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
9
 
8
10
  **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
11
 
12
+ [Checkout our Contributors!](#contri)
13
+
10
14
  ## ✨ Features
11
15
 
12
16
  - 💪 **Powerful** - Transform, validate, analyze, and format strings with minimal code
@@ -54,6 +58,7 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
54
58
  - [toSlug](#toslug) - Converts a string to a URL-friendly slug
55
59
  - [capitalizeWords](#capitalizewords) - Capitalizes the first letter of each word
56
60
  - [removeSpecialChars](#removespecialchars) - Removes special characters from a string
61
+ - [removeWords](#removewords) - Removes specified words from a string
57
62
  - [camelCase](#camelcase) - Converts the given string to Camel Case
58
63
  - [pascaslCase](#pascalcase) - Converts the given string to Pascal Case
59
64
  - [snakeCase](#snakecase) - Converts the given string to Snake Case
@@ -64,6 +69,7 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
64
69
  ### Validations
65
70
  - [isURL](#isurl) - Checks if a string is a valid URL
66
71
  - [isEmail](#isemail) - Checks if a string is a valid email address
72
+ - [isDate](#isdate) - Checks if a string is a valid date
67
73
  - [isEmpty](#isempty) - Checks if a string is empty or contains only whitespace
68
74
 
69
75
  ### Analysis
@@ -169,6 +175,28 @@ removeSpecialChars('Phone: (123) 456-7890', '-');
169
175
  | text | string | required | The input string to process |
170
176
  | replacement | string | '' | String to replace special characters with |
171
177
 
178
+ #### <a id="removewords"></a>`removeWords(text, wordsToRemove)`
179
+
180
+ Removes specified words from a string
181
+
182
+ ```javascript
183
+ import { removeWords } from 'stringzy';
184
+
185
+ removeWords('Hello world this is a test', ['this', 'is']);
186
+ // Returns: 'Hello world a test'
187
+
188
+ removeWords('Remove The Quick BROWN fox', ['the', 'brown']);
189
+ // Returns: 'Remove Quick fox'
190
+
191
+ removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']);
192
+ // Returns: 'is awesome and rocks'
193
+ ```
194
+
195
+ | Parameter | Type | Default | Description |
196
+ |-----------|------|---------|-------------|
197
+ | text | string | required | The input string to process |
198
+ | wordsToRemove | string[] | required | Array of words to remove from the string |
199
+
172
200
  #### <a id="camelcase"></a>`camelCase(text)`
173
201
 
174
202
  Converts the given string to Camel Case.
@@ -294,6 +322,23 @@ isEmail('invalid-email'); // false
294
322
  |-----------|------|---------|-------------|
295
323
  | text | string | required | The input string to validate as email |
296
324
 
325
+ #### <a id="isdate"></a>`isDate(text)`
326
+
327
+ Checks if a string is a valid date.
328
+
329
+ ```javascript
330
+ import { isDate } from 'stringzy';
331
+
332
+ isDate('2023-12-25'); // true
333
+ isDate('12/25/2023'); // true
334
+ isDate('invalid-date'); // false
335
+ isDate('2023-13-45'); // false
336
+ ```
337
+
338
+ | Parameter | Type | Default | Description |
339
+ |-----------|------|---------|-------------|
340
+ | text | string | required | The input string to validate as date |
341
+
297
342
  #### <a id="isempty"></a>`isEmpty(text)`
298
343
 
299
344
  Checks if a string is empty or contains only whitespace.
@@ -541,6 +586,47 @@ Contributions are welcome! Please feel free to submit a Pull Request.
541
586
  4. Push to the branch (`git push origin feature/amazing-feature`)
542
587
  5. Open a Pull Request
543
588
 
589
+
590
+ ## <a id="contri"></a>`Contributors`
591
+
592
+ <table>
593
+ <tbody>
594
+ <tr>
595
+ <td align="center">
596
+ <a href="https://github.com/Samarth2190">
597
+ <img src="https://avatars.githubusercontent.com/Samarth2190" width="100px;"
598
+ alt="Samarth Ruia" />
599
+ <br />
600
+ <sub>
601
+ <b>Samarth Ruia</b>
602
+ </sub>
603
+ </a>
604
+ </td>
605
+ <td align="center">
606
+ <a href="https://github.com/JohnCervantes">
607
+ <img src="https://avatars.githubusercontent.com/JohnCervantes" width="100px;"
608
+ alt="John Cervantes" />
609
+ <br />
610
+ <sub>
611
+ <b>John Cervantes</b>
612
+ </sub>
613
+ </a>
614
+ </td>
615
+ <td align="center">
616
+ <a href="https://github.com/thehardiik">
617
+ <img src="https://avatars.githubusercontent.com/thehardiik" width="100px;"
618
+ alt="Hardik Srivastav" />
619
+ <br />
620
+ <sub>
621
+ <b>Hardik Srivastav</b>
622
+ </sub>
623
+ </a>
624
+ </td>
625
+ </tr>
626
+ </tbody>
627
+ </table>
628
+
629
+
544
630
  ## 📝 License
545
631
 
546
632
  This project is licensed under the MIT License - see the LICENSE file for details.
@@ -550,6 +636,8 @@ This project is licensed under the MIT License - see the LICENSE file for detail
550
636
  - Thank you to all contributors and users of this package!
551
637
  - Inspired by the need for comprehensive yet simple string manipulation utilities.
552
638
 
639
+ 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!
640
+
553
641
  ---
554
642
 
555
643
  Made with ❤️ by Samarth Ruia
package/changelog.txt CHANGED
@@ -1,6 +1,16 @@
1
1
  CHANGELOG
2
2
 
3
3
  All notable changes to the `stringzy` package will be documented in this file.
4
+ =============================================================================
5
+ Version 2.1.0 - 2025-05-31
6
+ -----------------------------------------------------------------------------
7
+
8
+ ADDED:
9
+ - Added new utility functions:
10
+ - `removeWords`:
11
+ - `isDate`: Validates if a string is a valid date
12
+ - Added contributors section in README
13
+ - Added new badges for open source and PRs
4
14
 
5
15
  =============================================================================
6
16
  Version 2.0.1 - 2025-05-23
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.1.0
11
11
  */
12
12
 
13
13
  import * as transformations from './transformations.js';
@@ -27,12 +27,14 @@ export const {
27
27
  kebabCase,
28
28
  titleCase,
29
29
  constantCase,
30
+ removeWords,
30
31
  } = transformations;
31
32
 
32
33
  export const {
33
34
  isURL,
34
35
  isEmail,
35
- isEmpty
36
+ isEmpty,
37
+ isDate,
36
38
  } = validations;
37
39
 
38
40
  export const {
@@ -64,4 +66,8 @@ export default {
64
66
  analyze: analysis,
65
67
  format: formatting,
66
68
 
67
- };
69
+ transform,
70
+ validate,
71
+ analyze,
72
+ format,
73
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stringzy",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -125,4 +125,25 @@ 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
+ }
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
+