mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
34 lines
786 B
JavaScript
34 lines
786 B
JavaScript
import castSlice from './castSlice.js'
|
|
import hasUnicode from './hasUnicode.js'
|
|
import stringToArray from './stringToArray.js'
|
|
import toString from '../toString.js'
|
|
|
|
/**
|
|
* Creates a function like `lowerFirst`.
|
|
*
|
|
* @private
|
|
* @param {string} methodName The name of the `String` case method to use.
|
|
* @returns {Function} Returns the new case function.
|
|
*/
|
|
function createCaseFirst(methodName) {
|
|
return string => {
|
|
string = toString(string)
|
|
|
|
const strSymbols = hasUnicode(string)
|
|
? stringToArray(string)
|
|
: undefined
|
|
|
|
const chr = strSymbols
|
|
? strSymbols[0]
|
|
: string[0]
|
|
|
|
const trailing = strSymbols
|
|
? castSlice(strSymbols, 1).join('')
|
|
: string.slice(1)
|
|
|
|
return chr[methodName]() + trailing
|
|
}
|
|
}
|
|
|
|
export default createCaseFirst
|