smart-string-formatter 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.
Files changed (3) hide show
  1. package/index.js +31 -0
  2. package/package.json +21 -0
  3. package/test.js +13 -0
package/index.js ADDED
@@ -0,0 +1,31 @@
1
+ function smartFormat(str) {
2
+ if (!str || typeof str !== 'string') {
3
+ return { camel: '', pascal: '', snake: '', kebab: '', slug: '' };
4
+ }
5
+ const normalized = str
6
+ .normalize('NFD').replace(/[\u0300-\u036f]/g, '')
7
+ .replace(/[^a-zA-Z0-9\s-_]/g, ' ')
8
+ .replace(/[-_]/g, ' ')
9
+ .trim()
10
+ .replace(/\s+/g, ' ');
11
+
12
+ const words = normalized.split(' ');
13
+
14
+ // 2. Generate Formats
15
+ const camel = words
16
+ .map((w, i) => i === 0 ? w.toLowerCase() : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
17
+ .join('');
18
+
19
+ const pascal = words
20
+ .map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
21
+ .join('');
22
+
23
+ const snake = words.map(w => w.toLowerCase()).join('_');
24
+
25
+ const kebab = words.map(w => w.toLowerCase()).join('-');
26
+
27
+ const slug = kebab;
28
+ return { camel, pascal, snake, kebab, slug };
29
+ }
30
+
31
+ module.exports = smartFormat;
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "smart-string-formatter",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight, zero-dependency utility to instantly convert strings into CamelCase, PascalCase, Snake_Case, Kebab-Case, and URL-friendly Slugs. Handles special characters, irregular spacing, and accents automatically.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js",
8
+ "start":"node index.js"
9
+ },
10
+ "keywords": [
11
+ "string",
12
+ "formatter",
13
+ "camelcase",
14
+ "slugify",
15
+ "utils",
16
+ "case-converter",
17
+ "slug"
18
+ ],
19
+ "author": "Gayathree",
20
+ "license": "MIT"
21
+ }
package/test.js ADDED
@@ -0,0 +1,13 @@
1
+ const formatter = require('./index');
2
+
3
+ const input = " Hello @World_from-NodeJS!! ";
4
+ const results = formatter(input);
5
+
6
+ console.log("Testing Input:", input);
7
+ console.table(results);
8
+
9
+ // Expected Output:
10
+ // camel: helloWorldFromNodejs
11
+ // pascal: HelloWorldFromNodejs
12
+ // snake: hello_world_from_nodejs
13
+ // kebab: hello-world-from-nodejs