You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
811 B

4 years ago
  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;