Remove createCompounder.

This commit is contained in:
John-David Dalton
2017-03-26 21:27:06 -07:00
parent 4b80666a30
commit d7bdf0ae25
7 changed files with 32 additions and 39 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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