diff --git a/public/data/javascript.json b/public/data/javascript.json index d81f40dd..5aafb086 100644 --- a/public/data/javascript.json +++ b/public/data/javascript.json @@ -218,6 +218,62 @@ "tags": ["string", "case", "snake_case"], "author": "axorax" }, + { + "title": "Convert String to Camel Case", + "description": "Converts a given string into camelCase.", + "code": [ + "function toCamelCase(str) {", + " return str.replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());", + "}", + "", + "// Example usage:", + "console.log(toCamelCase('hello world test')); // Output: 'helloWorldTest'" + ], + "tags": ["string", "case", "camelCase"], + "author": "aumirza" + }, + { + "title": "Convert String to Title Case", + "description": "Converts a given string into Title Case.", + "code": [ + "function toTitleCase(str) {", + " return str.toLowerCase().replace(/\\b\\w/g, (s) => s.toUpperCase());", + "}", + "", + "// Example usage:", + "console.log(toTitleCase('hello world test')); // Output: 'Hello World Test'" + ], + "tags": ["string", "case", "titleCase"], + "author": "aumirza" + }, + { + "title": "Convert String to Pascal Case", + "description": "Converts a given string into Pascal Case.", + "code": [ + "function toPascalCase(str) {", + " return str.replace(/\\b\\w/g, (s) => s.toUpperCase()).replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());", + "}", + "", + "// Example usage:", + "console.log(toPascalCase('hello world test')); // Output: 'HelloWorldTest'" + ], + "tags": ["string", "case", "pascalCase"], + "author": "aumirza" + }, + { + "title": "Convert String to Param Case", + "description": "Converts a given string into param-case.", + "code": [ + "function toParamCase(str) {", + " return str.toLowerCase().replace(/\\s+/g, '-');", + "}", + "", + "// Example usage:", + "console.log(toParamCase('Hello World Test')); // Output: 'hello-world-test'" + ], + "tags": ["string", "case", "paramCase"], + "author": "aumirza" + }, { "title": "Remove Vowels from a String", "description": "Removes all vowels from a given string.", @@ -950,5 +1006,48 @@ "author": "realvishalrana" } ] + }, + { + "categoryName": "Regular expression", + "snippets": [ + { + "title": "Regex Match Utility Function", + "description": "Enhanced regular expression matching utility.", + "code": [ + "/**", + "* @param {string | number} input", + "* The input string to match", + "* @param {regex | string} expression", + "* Regular expression", + "* @param {string} flags", + "* Optional Flags", + "*", + "* @returns {array}", + "* [{", + "* match: '...',", + "* matchAtIndex: 0,", + "* capturedGroups: [ '...', '...' ]", + "* }]", + "*/", + "function regexMatch(input, expression, flags = 'g') {", + " let regex =", + " expression instanceof RegExp", + " ? expression", + " : new RegExp(expression, flags);", + " let matches = input.matchAll(regex);", + " matches = [...matches];", + " return matches.map((item) => {", + " return {", + " match: item[0],", + " matchAtIndex: item.index,", + " capturedGroups: item.length > 1 ? item.slice(1) : undefined,", + " };", + " });", + "}" + ], + "tags": ["javascript","regex"], + "author": "aumirza" + } + ] } ]