Skip to content

Commit

Permalink
Ensure the separator argument is a string
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
sindresorhus committed Mar 21, 2019
1 parent 3e9b40a commit 19a4230
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
const xRegExp = require('xregexp');

const decamelize = (text, separator) => {
if (typeof text !== 'string') {
throw new TypeError('Expected a string');
const decamelize = (text, separator = '_') => {
if (!(typeof text === 'string' && typeof text === 'string')) {
throw new TypeError('The `text` and `separator` arguments should be of type `string`');
}

separator = typeof separator === 'undefined' ? '_' : separator;

const regex1 = xRegExp('([\\p{Ll}\\d])(\\p{Lu})', 'g');
const regex2 = xRegExp('(\\p{Lu}+)(\\p{Lu}[\\p{Ll}\\d]+)', 'g');

Expand Down

0 comments on commit 19a4230

Please sign in to comment.