stringzy 1.0.0 → 1.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/LICENSE +21 -0
- package/README.md +0 -0
- package/index.js +23 -9
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Samarth Ruia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
Binary file
|
package/index.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
export function truncateText(text, maxLength, suffix = '...') {
|
|
2
|
+
if (typeof text !== 'string') {
|
|
3
|
+
throw new Error("Input text must be a string.");
|
|
4
|
+
}
|
|
5
|
+
if (typeof maxLength !== 'number' || maxLength < 0) {
|
|
6
|
+
throw new Error("maxLength must be a non-negative number.");
|
|
7
|
+
}
|
|
8
|
+
if (typeof suffix !== 'string') {
|
|
9
|
+
throw new Error("Suffix must be a string.");
|
|
10
|
+
}
|
|
1
11
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
throw new Error("Invalid arguments. Expected (string, number).");
|
|
12
|
+
if (text.length <= maxLength) {
|
|
13
|
+
return text;
|
|
5
14
|
}
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
|
|
16
|
+
const adjustedLength = maxLength - suffix.length;
|
|
17
|
+
return text.slice(0, adjustedLength > 0 ? adjustedLength : 0) + suffix;
|
|
18
|
+
}
|
|
8
19
|
|
|
9
20
|
|
|
10
21
|
export function toSlug(text) {
|
|
@@ -26,10 +37,13 @@ export function truncateText(text, length) {
|
|
|
26
37
|
return text.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
export function removeSpecialChars(text) {
|
|
40
|
+
export function removeSpecialChars(text, replacement = '') {
|
|
30
41
|
if (typeof text !== "string") {
|
|
31
|
-
|
|
42
|
+
throw new Error("Invalid argument. Expected a string.");
|
|
32
43
|
}
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
if (typeof replacement !== "string") {
|
|
45
|
+
throw new Error("Replacement must be a string.");
|
|
46
|
+
}
|
|
47
|
+
return text.replace(/[^\w\s]/gi, replacement);
|
|
48
|
+
}
|
|
35
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stringzy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
],
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/Samarth2190/
|
|
36
|
+
"url": "git+https://github.com/Samarth2190/stringzy.git"
|
|
37
37
|
}
|
|
38
38
|
}
|