Skip to content

Commit

Permalink
Merge pull request #63 from aumirza/main
Browse files Browse the repository at this point in the history
Added regex category, and few case change snippets in string manipulation JavaScript.
  • Loading branch information
Mathys-Gasnier authored Dec 31, 2024
2 parents 69e9d13 + b436fb9 commit a4ba247
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions public/data/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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"
}
]
}
]

0 comments on commit a4ba247

Please sign in to comment.