diff --git a/.internal/createCompounder.js b/.internal/createCompounder.js deleted file mode 100644 index 8fc76fa41..000000000 --- a/.internal/createCompounder.js +++ /dev/null @@ -1,19 +0,0 @@ -import words from '../words.js' - -/** Used to match apostrophes. */ -const reApos = /['\u2019]/g - -/** - * Creates a function like `camelCase`. - * - * @private - * @param {Function} callback The function to combine each word. - * @returns {Function} Returns the new compounder function. - */ -function createCompounder(callback) { - return (string) => ( - words(`${ string }`.replace(reApos, '')).reduce(callback, '') - ) -} - -export default createCompounder diff --git a/camelCase.js b/camelCase.js index 44814a851..91b40abc9 100644 --- a/camelCase.js +++ b/camelCase.js @@ -1,5 +1,5 @@ import capitalize from './capitalize.js' -import createCompounder from './.internal/createCompounder.js' +import words from './words.js' /** * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). @@ -20,9 +20,11 @@ import createCompounder from './.internal/createCompounder.js' * camelCase('__FOO_BAR__') * // => 'fooBar' */ -const camelCase = createCompounder((result, word, index) => { - word = word.toLowerCase() - return result + (index ? capitalize(word) : word) -}) +const camelCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => { + word = word.toLowerCase() + return result + (index ? capitalize(word) : word) + }, '') +) export default camelCase diff --git a/kebabCase.js b/kebabCase.js index a296a6e8d..4f942cbc4 100644 --- a/kebabCase.js +++ b/kebabCase.js @@ -1,4 +1,4 @@ -import createCompounder from './.internal/createCompounder.js' +import words from './words.js' /** * Converts `string` to @@ -20,8 +20,10 @@ import createCompounder from './.internal/createCompounder.js' * kebabCase('__FOO_BAR__') * // => 'foo-bar' */ -const kebabCase = createCompounder((result, word, index) => - result + (index ? '-' : '') + word.toLowerCase() +const kebabCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? '-' : '') + word.toLowerCase() + ), '') ) export default kebabCase diff --git a/lowerCase.js b/lowerCase.js index 11f28eba2..616557b93 100644 --- a/lowerCase.js +++ b/lowerCase.js @@ -1,4 +1,4 @@ -import createCompounder from './.internal/createCompounder.js' +import words from './words.js' /** * Converts `string`, as space separated words, to lower case. @@ -19,8 +19,10 @@ import createCompounder from './.internal/createCompounder.js' * lowerCase('__FOO_BAR__') * // => 'foo bar' */ -const lowerCase = createCompounder((result, word, index) => - result + (index ? ' ' : '') + word.toLowerCase() +const lowerCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + word.toLowerCase() + ), '') ) export default lowerCase diff --git a/snakeCase.js b/snakeCase.js index 7a4cc2667..fa3e61ed5 100644 --- a/snakeCase.js +++ b/snakeCase.js @@ -1,4 +1,4 @@ -import createCompounder from './.internal/createCompounder.js' +import words from './words.js' /** * Converts `string` to @@ -20,8 +20,10 @@ import createCompounder from './.internal/createCompounder.js' * snakeCase('--FOO-BAR--') * // => 'foo_bar' */ -const snakeCase = createCompounder((result, word, index) => - result + (index ? '_' : '') + word.toLowerCase() +const snakeCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? '_' : '') + word.toLowerCase() + ), '') ) export default snakeCase diff --git a/startCase.js b/startCase.js index 4c6b6e855..32bf70557 100644 --- a/startCase.js +++ b/startCase.js @@ -1,5 +1,5 @@ -import createCompounder from './.internal/createCompounder.js' import upperFirst from './upperFirst.js' +import words from './words.js' /** * Converts `string` to @@ -21,8 +21,10 @@ import upperFirst from './upperFirst.js' * startCase('__FOO_BAR__') * // => 'FOO BAR' */ -const startCase = createCompounder((result, word, index) => - result + (index ? ' ' : '') + upperFirst(word) +const startCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + upperFirst(word) + ), '') ) export default startCase diff --git a/upperCase.js b/upperCase.js index 97bf1b091..c75f22232 100644 --- a/upperCase.js +++ b/upperCase.js @@ -1,4 +1,4 @@ -import createCompounder from './.internal/createCompounder.js' +import words from './words.js' /** * Converts `string`, as space separated words, to upper case. @@ -19,8 +19,10 @@ import createCompounder from './.internal/createCompounder.js' * upperCase('__foo_bar__') * // => 'FOO BAR' */ -const upperCase = createCompounder((result, word, index) => - result + (index ? ' ' : '') + word.toUpperCase() +const upperCase = (string) => ( + words(`${ string }`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + word.toUpperCase() + ), '') ) export default upperCase