Commit 46c21997 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'chore/slugify-duplication-removal' into 'master'

Remove duplication from slugifyWithUnderscore function

Closes #12321

See merge request gitlab-org/gitlab!20016
parents 5d5b707c 04a29b1b
......@@ -36,25 +36,26 @@ export const humanize = string =>
export const dasherize = str => str.replace(/[_\s]+/g, '-');
/**
* Replaces whitespaces with hyphens, convert to lower case and remove non-allowed special characters
* @param {String} str
* Replaces whitespace and non-sluggish characters with a given separator
* @param {String} str - The string to slugify
* @param {String=} separator - The separator used to separate words (defaults to "-")
* @returns {String}
*/
export const slugify = str => {
export const slugify = (str, separator = '-') => {
const slug = str
.trim()
.toLowerCase()
.replace(/[^a-zA-Z0-9_.-]+/g, '-');
.replace(/[^a-zA-Z0-9_.-]+/g, separator);
return slug === '-' ? '' : slug;
return slug === separator ? '' : slug;
};
/**
* Replaces whitespaces with underscore and converts to lower case
* Replaces whitespace and non-sluggish characters with underscores
* @param {String} str
* @returns {String}
*/
export const slugifyWithUnderscore = str => str.toLowerCase().replace(/\s+/g, '_');
export const slugifyWithUnderscore = str => slugify(str, '_');
/**
* Truncates given text
......
---
title: Remove duplication from slugifyWithUnderscore function
merge_request: 20016
author: Arun Kumar Mohan
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment