|
2 | 2 | {
|
3 | 3 | "categoryName": "Array Manipulation",
|
4 | 4 | "snippets": [
|
5 |
| - { |
6 |
| - "title": "Slugify String", |
7 |
| - "description": "Converts a string into a URL-friendly slug format.", |
8 |
| - "code": [ |
9 |
| - "const slugify = (string, separator = \"-\") => {", |
10 |
| - " return string", |
11 |
| - " .toString() // Cast to string (optional)", |
12 |
| - " .toLowerCase() // Convert the string to lowercase letters", |
13 |
| - " .trim() // Remove whitespace from both sides of a string (optional)", |
14 |
| - " .replace(/\\s+/g, separator) // Replace spaces with {separator}", |
15 |
| - " .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars", |
16 |
| - " .replace(/\\_/g, separator) // Replace _ with {separator}", |
17 |
| - " .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}", |
18 |
| - " .replace(/\\-$/g, \"\"); // Remove trailing -", |
19 |
| - "};", |
20 |
| - "", |
21 |
| - "// Usage:", |
22 |
| - "const title = \"Hello, World! This is a Test.\";", |
23 |
| - "console.log(slugify(title)); // Output: 'hello-world-this-is-a-test'", |
24 |
| - "console.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'" |
25 |
| - ], |
26 |
| - "tags": ["javascript", "string", "slug", "utility"], |
27 |
| - "author": "technoph1le" |
28 |
| - }, |
29 | 5 | {
|
30 | 6 | "title": "Remove Duplicates",
|
31 | 7 | "description": "Removes duplicate values from an array.",
|
|
57 | 33 | {
|
58 | 34 | "categoryName": "String Manipulation",
|
59 | 35 | "snippets": [
|
| 36 | + { |
| 37 | + "title": "Slugify String", |
| 38 | + "description": "Converts a string into a URL-friendly slug format.", |
| 39 | + "code": [ |
| 40 | + "const slugify = (string, separator = \"-\") => {", |
| 41 | + " return string", |
| 42 | + " .toString() // Cast to string (optional)", |
| 43 | + " .toLowerCase() // Convert the string to lowercase letters", |
| 44 | + " .trim() // Remove whitespace from both sides of a string (optional)", |
| 45 | + " .replace(/\\s+/g, separator) // Replace spaces with {separator}", |
| 46 | + " .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars", |
| 47 | + " .replace(/\\_/g, separator) // Replace _ with {separator}", |
| 48 | + " .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}", |
| 49 | + " .replace(/\\-$/g, \"\"); // Remove trailing -", |
| 50 | + "};", |
| 51 | + "", |
| 52 | + "// Usage:", |
| 53 | + "const title = \"Hello, World! This is a Test.\";", |
| 54 | + "console.log(slugify(title)); // Output: 'hello-world-this-is-a-test'", |
| 55 | + "console.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'" |
| 56 | + ], |
| 57 | + "tags": ["javascript", "string", "slug", "utility"], |
| 58 | + "author": "technoph1le" |
| 59 | + }, |
60 | 60 | {
|
61 | 61 | "title": "Capitalize String",
|
62 | 62 | "description": "Capitalizes the first letter of a string.",
|
|
0 commit comments