Skip to content

Commit 9122e57

Browse files
TiagoDaninsindresorhus
authored andcommittedJan 21, 2020
Separate capitalized words (#36)
1 parent 5220d93 commit 9122e57

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

‎index.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const builtinOverridableReplacements = require('./overridable-replacements');
66

77
const decamelize = string => {
88
return string
9+
// Separate capitalized words.
10+
.replace(/([A-Z]{2,})([a-z\d]+)/g, '$1 $2')
11+
.replace(/([a-z\d]+)([A-Z]{2,})/g, '$1 $2')
12+
913
.replace(/([a-z\d])([A-Z])/g, '$1 $2')
1014
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1 $2');
1115
};

‎test.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ test('main', t => {
2121
t.is(slugify('foo🦄'), 'foo-unicorn');
2222
t.is(slugify('🦄🦄🦄'), 'unicorn-unicorn-unicorn');
2323
t.is(slugify('foo&bar'), 'foo-and-bar');
24+
t.is(slugify('foo360BAR'), 'foo360-bar');
25+
t.is(slugify('FOO360'), 'foo-360');
26+
t.is(slugify('FOObar'), 'foo-bar');
2427
});
2528

2629
test('custom separator', t => {

0 commit comments

Comments
 (0)
Please sign in to comment.