Skip to content

Commit a4ba247

Browse files
Merge pull request #63 from aumirza/main
Added regex category, and few case change snippets in string manipulation JavaScript.
2 parents 69e9d13 + b436fb9 commit a4ba247

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

public/data/javascript.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,62 @@
218218
"tags": ["string", "case", "snake_case"],
219219
"author": "axorax"
220220
},
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+
},
221277
{
222278
"title": "Remove Vowels from a String",
223279
"description": "Removes all vowels from a given string.",
@@ -950,5 +1006,48 @@
9501006
"author": "realvishalrana"
9511007
}
9521008
]
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+
]
9531052
}
9541053
]

0 commit comments

Comments
 (0)