Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -935,5 +991,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"
}
]
}
]