|
218 | 218 | "tags": ["string", "case", "snake_case"],
|
219 | 219 | "author": "axorax"
|
220 | 220 | },
|
| 221 | + { |
| 222 | + "title": "Convert String to Camel Case", |
| 223 | + "description": "Converts a given string into camelCase.", |
| 224 | + "code": [ |
| 225 | + "function toCamelCase(str) {", |
| 226 | + " return str.replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());", |
| 227 | + "}", |
| 228 | + "", |
| 229 | + "// Example usage:", |
| 230 | + "console.log(toCamelCase('hello world test')); // Output: 'helloWorldTest'" |
| 231 | + ], |
| 232 | + "tags": ["string", "case", "camelCase"], |
| 233 | + "author": "aumirza" |
| 234 | + }, |
| 235 | + { |
| 236 | + "title": "Convert String to Title Case", |
| 237 | + "description": "Converts a given string into Title Case.", |
| 238 | + "code": [ |
| 239 | + "function toTitleCase(str) {", |
| 240 | + " return str.toLowerCase().replace(/\\b\\w/g, (s) => s.toUpperCase());", |
| 241 | + "}", |
| 242 | + "", |
| 243 | + "// Example usage:", |
| 244 | + "console.log(toTitleCase('hello world test')); // Output: 'Hello World Test'" |
| 245 | + ], |
| 246 | + "tags": ["string", "case", "titleCase"], |
| 247 | + "author": "aumirza" |
| 248 | + }, |
| 249 | + { |
| 250 | + "title": "Convert String to Pascal Case", |
| 251 | + "description": "Converts a given string into Pascal Case.", |
| 252 | + "code": [ |
| 253 | + "function toPascalCase(str) {", |
| 254 | + " return str.replace(/\\b\\w/g, (s) => s.toUpperCase()).replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());", |
| 255 | + "}", |
| 256 | + "", |
| 257 | + "// Example usage:", |
| 258 | + "console.log(toPascalCase('hello world test')); // Output: 'HelloWorldTest'" |
| 259 | + ], |
| 260 | + "tags": ["string", "case", "pascalCase"], |
| 261 | + "author": "aumirza" |
| 262 | + }, |
| 263 | + { |
| 264 | + "title": "Convert String to Param Case", |
| 265 | + "description": "Converts a given string into param-case.", |
| 266 | + "code": [ |
| 267 | + "function toParamCase(str) {", |
| 268 | + " return str.toLowerCase().replace(/\\s+/g, '-');", |
| 269 | + "}", |
| 270 | + "", |
| 271 | + "// Example usage:", |
| 272 | + "console.log(toParamCase('Hello World Test')); // Output: 'hello-world-test'" |
| 273 | + ], |
| 274 | + "tags": ["string", "case", "paramCase"], |
| 275 | + "author": "aumirza" |
| 276 | + }, |
221 | 277 | {
|
222 | 278 | "title": "Remove Vowels from a String",
|
223 | 279 | "description": "Removes all vowels from a given string.",
|
|
950 | 1006 | "author": "realvishalrana"
|
951 | 1007 | }
|
952 | 1008 | ]
|
| 1009 | + }, |
| 1010 | + { |
| 1011 | + "categoryName": "Regular expression", |
| 1012 | + "snippets": [ |
| 1013 | + { |
| 1014 | + "title": "Regex Match Utility Function", |
| 1015 | + "description": "Enhanced regular expression matching utility.", |
| 1016 | + "code": [ |
| 1017 | + "/**", |
| 1018 | + "* @param {string | number} input", |
| 1019 | + "* The input string to match", |
| 1020 | + "* @param {regex | string} expression", |
| 1021 | + "* Regular expression", |
| 1022 | + "* @param {string} flags", |
| 1023 | + "* Optional Flags", |
| 1024 | + "*", |
| 1025 | + "* @returns {array}", |
| 1026 | + "* [{", |
| 1027 | + "* match: '...',", |
| 1028 | + "* matchAtIndex: 0,", |
| 1029 | + "* capturedGroups: [ '...', '...' ]", |
| 1030 | + "* }]", |
| 1031 | + "*/", |
| 1032 | + "function regexMatch(input, expression, flags = 'g') {", |
| 1033 | + " let regex =", |
| 1034 | + " expression instanceof RegExp", |
| 1035 | + " ? expression", |
| 1036 | + " : new RegExp(expression, flags);", |
| 1037 | + " let matches = input.matchAll(regex);", |
| 1038 | + " matches = [...matches];", |
| 1039 | + " return matches.map((item) => {", |
| 1040 | + " return {", |
| 1041 | + " match: item[0],", |
| 1042 | + " matchAtIndex: item.index,", |
| 1043 | + " capturedGroups: item.length > 1 ? item.slice(1) : undefined,", |
| 1044 | + " };", |
| 1045 | + " });", |
| 1046 | + "}" |
| 1047 | + ], |
| 1048 | + "tags": ["javascript","regex"], |
| 1049 | + "author": "aumirza" |
| 1050 | + } |
| 1051 | + ] |
953 | 1052 | }
|
954 | 1053 | ]
|
0 commit comments