JAVASCRIPT   74

capitalize js

Guest on 26th June 2022 03:52:58 AM

  1. var baseToString = require('../internal/baseToString');
  2.  
  3. /**
  4.  * Capitalizes the first character of `string`.
  5.  *
  6.  * @static
  7.  * @memberOf _
  8.  * @category String
  9.  * @param {string} [string=''] The string to capitalize.
  10.  * @returns {string} Returns the capitalized string.
  11.  * @example
  12.  *
  13.  * _.capitalize('fred');
  14.  * // => 'Fred'
  15.  */
  16. function capitalize(string) {
  17.   string = baseToString(string);
  18.   return string && (string.charAt(0).toUpperCase() + string.slice(1));
  19. }
  20.  
  21. module.exports = capitalize;

Raw Paste


Login or Register to edit or fork this paste. It's free.