UNPKG

809 BJavaScriptView Raw
1import castSlice from './_castSlice.js';
2import hasUnicode from './_hasUnicode.js';
3import stringToArray from './_stringToArray.js';
4import toString from './toString.js';
5
6/**
7 * Creates a function like `_.lowerFirst`.
8 *
9 * @private
10 * @param {string} methodName The name of the `String` case method to use.
11 * @returns {Function} Returns the new case function.
12 */
13function createCaseFirst(methodName) {
14 return function(string) {
15 string = toString(string);
16
17 var strSymbols = hasUnicode(string)
18 ? stringToArray(string)
19 : undefined;
20
21 var chr = strSymbols
22 ? strSymbols[0]
23 : string.charAt(0);
24
25 var trailing = strSymbols
26 ? castSlice(strSymbols, 1).join('')
27 : string.slice(1);
28
29 return chr[methodName]() + trailing;
30 };
31}
32
33export default createCaseFirst;