mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Remove createCompounder.
This commit is contained in:
@@ -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
|
||||
12
camelCase.js
12
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user