5718f6f4aa8ef3e4d6b88008ba4190c4aec95c1d
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / _createCaseFirst.js
1 var stringToArray = require('./_stringToArray'),
2     toString = require('./toString');
3
4 /** Used to compose unicode character classes. */
5 var rsAstralRange = '\\ud800-\\udfff',
6     rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
7     rsComboSymbolsRange = '\\u20d0-\\u20f0',
8     rsVarRange = '\\ufe0e\\ufe0f';
9
10 /** Used to compose unicode capture groups. */
11 var rsZWJ = '\\u200d';
12
13 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
14 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange  + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
15
16 /**
17  * Creates a function like `_.lowerFirst`.
18  *
19  * @private
20  * @param {string} methodName The name of the `String` case method to use.
21  * @returns {Function} Returns the new function.
22  */
23 function createCaseFirst(methodName) {
24   return function(string) {
25     string = toString(string);
26
27     var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string) : undefined,
28         chr = strSymbols ? strSymbols[0] : string.charAt(0),
29         trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1);
30
31     return chr[methodName]() + trailing;
32   };
33 }
34
35 module.exports = createCaseFirst;