smart-string-utils 1.0.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/index.js +37 -0
- package/package.json +19 -0
package/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function capitalize(text) {
|
|
2
|
+
if (!text) return "";
|
|
3
|
+
return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function wordCount(text) {
|
|
7
|
+
if (!text) return 0;
|
|
8
|
+
return text.trim().split(/\s+/).length;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function reverseText(text) {
|
|
12
|
+
if (!text) return "";
|
|
13
|
+
return text.split("").reverse().join("");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isPalindrome(text) {
|
|
17
|
+
if (!text) return false;
|
|
18
|
+
const cleaned = text.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
19
|
+
return cleaned === cleaned.split("").reverse().join("");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function randomString(length = 8) {
|
|
23
|
+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
24
|
+
let result = "";
|
|
25
|
+
for (let i = 0; i < length; i++) {
|
|
26
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
capitalize,
|
|
33
|
+
wordCount,
|
|
34
|
+
reverseText,
|
|
35
|
+
isPalindrome,
|
|
36
|
+
randomString
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smart-string-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A useful utility package for string operations like capitalize, reverse, palindrome check, etc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"text",
|
|
11
|
+
"string",
|
|
12
|
+
"utils",
|
|
13
|
+
"capitalize",
|
|
14
|
+
"palindrome",
|
|
15
|
+
"npm"
|
|
16
|
+
],
|
|
17
|
+
"author": "Arshit",
|
|
18
|
+
"license": "ISC"
|
|
19
|
+
}
|