-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathslugify.js
More file actions
32 lines (31 loc) · 993 Bytes
/
slugify.js
File metadata and controls
32 lines (31 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import coerceToString from 'helper/string/coerce_to_string';
import kebabCase from 'case/kebab_case';
import latinise from 'manipulate/latinise';
import { REGEXP_NON_LATIN } from 'helper/reg_exp/const';
/**
* Slugifies the `subject`. Cleans the `subject` by replacing diacritics with corresponding latin characters.
*
* @function slugify
* @static
* @since 1.0.0
* @memberOf Manipulate
* @param {string} [subject=''] The string to slugify.
* @return {string} Returns the slugified string.
* @example
* v.slugify('Italian cappuccino drink');
* // => 'italian-cappuccino-drink'
*
* v.slugify('caffé latté');
* // => 'caffe-latte'
*
* v.slugify('хорошая погода');
* // => 'horoshaya-pogoda'
*/
export default function slugify(subject) {
const subjectString = coerceToString(subject);
if (subjectString === '') {
return '';
}
const cleanSubjectString = latinise(subjectString).replace(REGEXP_NON_LATIN, '-');
return kebabCase(cleanSubjectString);
}