Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Switched 'Slugify String' snippet into the String Manipulation category #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
technoph1le merged 1 commit into quicksnip-dev:main from psychlone77:issue-slugify-strings
Dec 28, 2024
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
48 changes: 24 additions & 24 deletions public/data/javascript.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@
{
"categoryName": "Array Manipulation",
"snippets": [
{
"title": "Slugify String",
"description": "Converts a string into a URL-friendly slug format.",
"code": [
"const slugify = (string, separator = \"-\") => {",
" return string",
" .toString() // Cast to string (optional)",
" .toLowerCase() // Convert the string to lowercase letters",
" .trim() // Remove whitespace from both sides of a string (optional)",
" .replace(/\\s+/g, separator) // Replace spaces with {separator}",
" .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars",
" .replace(/\\_/g, separator) // Replace _ with {separator}",
" .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}",
" .replace(/\\-$/g, \"\"); // Remove trailing -",
"};",
"",
"// Usage:",
"const title = \"Hello, World! This is a Test.\";",
"console.log(slugify(title)); // Output: 'hello-world-this-is-a-test'",
"console.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'"
],
"tags": ["javascript", "string", "slug", "utility"],
"author": "technoph1le"
},
{
"title": "Remove Duplicates",
"description": "Removes duplicate values from an array.",
Expand Down Expand Up @@ -57,6 +33,30 @@
{
"categoryName": "String Manipulation",
"snippets": [
{
"title": "Slugify String",
"description": "Converts a string into a URL-friendly slug format.",
"code": [
"const slugify = (string, separator = \"-\") => {",
" return string",
" .toString() // Cast to string (optional)",
" .toLowerCase() // Convert the string to lowercase letters",
" .trim() // Remove whitespace from both sides of a string (optional)",
" .replace(/\\s+/g, separator) // Replace spaces with {separator}",
" .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars",
" .replace(/\\_/g, separator) // Replace _ with {separator}",
" .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}",
" .replace(/\\-$/g, \"\"); // Remove trailing -",
"};",
"",
"// Usage:",
"const title = \"Hello, World! This is a Test.\";",
"console.log(slugify(title)); // Output: 'hello-world-this-is-a-test'",
"console.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'"
],
"tags": ["javascript", "string", "slug", "utility"],
"author": "technoph1le"
},
{
"title": "Capitalize String",
"description": "Capitalizes the first letter of a string.",
Expand Down

AltStyle によって変換されたページ (->オリジナル) /