Skip to content

Commit b4161e2

Browse files
authored
Merge pull request #1 from psychlone77/issue-slugify-strings
Switched 'Slugify String' snippet into the String Manipulation category
2 parents 4256139 + b981270 commit b4161e2

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

public/data/javascript.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22
{
33
"categoryName": "Array Manipulation",
44
"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-
},
295
{
306
"title": "Remove Duplicates",
317
"description": "Removes duplicate values from an array.",
@@ -57,6 +33,30 @@
5733
{
5834
"categoryName": "String Manipulation",
5935
"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+
},
6060
{
6161
"title": "Capitalize String",
6262
"description": "Capitalizes the first letter of a string.",

0 commit comments

Comments
 (0)