Skip to content

Commit

Permalink
Separate capitalized words (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin authored and sindresorhus committed Jan 21, 2020
1 parent 5220d93 commit 9122e57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const builtinOverridableReplacements = require('./overridable-replacements');

const decamelize = string => {
return string
// Separate capitalized words.
.replace(/([A-Z]{2,})([a-z\d]+)/g, '$1 $2')
.replace(/([a-z\d]+)([A-Z]{2,})/g, '$1 $2')

.replace(/([a-z\d])([A-Z])/g, '$1 $2')
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1 $2');
};
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test('main', t => {
t.is(slugify('foo🦄'), 'foo-unicorn');
t.is(slugify('🦄🦄🦄'), 'unicorn-unicorn-unicorn');
t.is(slugify('foo&bar'), 'foo-and-bar');
t.is(slugify('foo360BAR'), 'foo360-bar');
t.is(slugify('FOO360'), 'foo-360');
t.is(slugify('FOObar'), 'foo-bar');
});

test('custom separator', t => {
Expand Down

0 comments on commit 9122e57

Please sign in to comment.