just-kebab-case
Advanced tools
Comparing version 1.1.0 to 2.0.0
16
index.js
@@ -11,3 +11,3 @@ module.exports = kebabCase; | ||
kebabCase('the - quick * brown# fox'); // 'the-quick-brown-fox' | ||
kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox' | ||
kebabCase('theQUICKBrownFox'); // 'the-quick-brown-fox' | ||
*/ | ||
@@ -18,8 +18,16 @@ | ||
var wordSeparators = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/; | ||
var capitals = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g; | ||
var capital_plus_lower = /[A-ZÀ-Ý\u00C0-\u00D6\u00D9-\u00DD][a-zà-ÿ]/g; | ||
var capitals = /[A-ZÀ-Ý\u00C0-\u00D6\u00D9-\u00DD]+/g; | ||
function kebabCase(str) { | ||
//replace capitals with space + lower case equivalent for later parsing | ||
// replace word starts with space + lower case equivalent for later parsing | ||
// 1) treat cap + lower as start of new word | ||
str = str.replace(capital_plus_lower, function(match) { | ||
// match is one caps followed by one non-cap | ||
return ' ' + (match[0].toLowerCase() || match[0]) + match[1]; | ||
}); | ||
// 2) treat all remaining capitals as words | ||
str = str.replace(capitals, function(match) { | ||
return ' ' + (match.toLowerCase() || match); | ||
// match is a series of caps | ||
return ' ' + match.toLowerCase(); | ||
}); | ||
@@ -26,0 +34,0 @@ return str |
{ | ||
"name": "just-kebab-case", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "convert a string to kebab case", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
@@ -22,2 +23,2 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4051
6
50