_createCaseFirst.js 811B

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