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.
- package/index.js +18 -0
- package/package.json +12 -0
- 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
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);
|