fullstack_cca2 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 +18 -0
  2. package/package.json +12 -0
  3. package/test.js +14 -0
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // index.js
2
+ // This file contains the custom utility function
3
+
4
+ function formatString(str) {
5
+ // Remove extra spaces from both ends and split words
6
+ let words = str.trim().split(/\s+/);
7
+
8
+ // Convert each word to Title Case
9
+ let result = words.map(word => {
10
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
11
+ });
12
+
13
+ // Join the words back into a single string
14
+ return result.join(" ");
15
+ }
16
+
17
+ // Export the function so that other files can use it
18
+ module.exports = formatString;
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "fullstack_cca2",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": ""
12
+ }
package/test.js ADDED
@@ -0,0 +1,14 @@
1
+ // test.js
2
+ // This file imports and tests the custom module
3
+
4
+ const formatString = require('./index');
5
+
6
+ // Sample input
7
+ let text = " hello node js world ";
8
+
9
+ // Call the function
10
+ let output = formatString(text);
11
+
12
+ // Display result
13
+ console.log("Original String:", text);
14
+ console.log("Formatted String:", output);