Javascript String capitalize()

Description

Javascript String capitalize()


String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1); 
};

function word_cap(str) {
  return str.split(' ').map(function(word) {
    return word.capitalize();
  }).join(' ');//from   ww w.  ja v a 2  s.  co  m
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript string capitalize()

string.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function(){
   return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
  };// ww w . j  a va  2  s  .  co  m

Javascript String capitalize()

/*//w w  w.j  av  a 2  s.c  om
    Capitalize the first letter of words
*/

String.prototype.capitalize = function () {
    'use strict';
    return this.replace(/(?:^|\s)\S/g, function (a) {
        return a.toUpperCase();
    });
};

Javascript String capitalize()

'use strict';/*from   w w w. j a v  a  2  s  . c o m*/
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};

Javascript String capitalize()

dojo.provide("cvdj.capstring");

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

function capitalize() {
  const text = this;/*  w  ww. j a  va2  s. com*/
  return text
    ? [text[0].toUpperCase(), text.slice(1)].join('')
    : text;
}

String.prototype.capitalize = capitalize;

Javascript String capitalize()

"use strict";/*  w  w  w  .  j  ava 2s . com*/
String.prototype.capitalize = String.prototype.capitalize || function() {
  var first = this.substring(0, 1);
  return first.toUpperCase() + this.substring(1);
};

Javascript String capitalize()

String.prototype.capitalize = function(){
  return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
};

Javascript String capitalize()

Function.isFunction = function (f) {
  return 'function' == typeof (f);
}

String.prototype.capitalize = function () {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

/*//from  ww w . j a v a 2  s  . co m
* Include with eval(fs.readFileSync());
*/

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.replace(/\b\w/g, function(l){ return l.toUpperCase() });
};

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};

Javascript String capitalize()

/**/*ww  w.  j  av a2 s.  c  o m*/
 * Capitalize a string
 * @return {String}
 */
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

var currentTask;//from   www. ja  va 2s.  co  m

//Dictionary of words
var dictionary = {};
var validWordArray = new Array();

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

var mainUrl = 'MY DOMAIN IN USE';


/** Funcion para capitalizar **/
String.prototype.capitalize = function() {
    return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this[0].toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

//Include helper functions here

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

function testAlert(name) {
  alert("."+name);
};

Javascript String capitalize()

String.prototype.capitalize = function () {
    'use strict';
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};

Javascript String capitalize()

/**/*from www .j a  v a2s .  c o m*/
 * Capitalizes the first letter of the string.
 * @returns {string} The string with the first letter capitalized.
 */
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function(){
  var first_char = this.charAt(0).toUpperCase();
  return this.replace(/^./,first_char);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

export default {};/*from w w w . j a v  a 2  s. c o m*/

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.replace(/(^|\/)([a-z])/g, (match) => match.toUpperCase());
}

export default String;/*from   w w  w . j  a va2 s  .co  m*/

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1)
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.slice(0, 1).toUpperCase() + this.slice(1).toLowerCase();
};

Javascript String capitalize()

String.prototype.capitalize = function() { 
  return this[0].toUpperCase() + this.slice(1); 
};

Javascript String capitalize()

// Capitalize the first letter of the string
String.prototype.capitalize = function () {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.trim()
             .split(' ')
             .map(word => {// w ww. ja  v  a 2 s.  co m
                return word.replace(/^[a-z]/g, word.charAt(0).toUpperCase())
             })
             .join(' ')
}

Javascript String capitalize()

'use strict'//from  w w  w .j  a va2 s.c  o  m

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

const idlescape = {}
idlescape.vues = {}
idlescape.models = {}
idlescape.models.spots = {}

idlescape.player = {}
idlescape.player.bank = {}

Javascript String capitalize()

String.prototype.capitalize=function(){
  return this[0].toUpperCase()+this.slice(1).toLowerCase()
}

function cleanItUp(s) {
  var rs=s.replace(/[^a-z]+/gi, '')
  return rs.length<5 ? '' : rs.match(/.{5}/g).map(e=>e.capitalize()).join` `
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

function titleize(array, callback) {
  let words = array.map(function(word) {
    return word.charAt(0).toUpperCase() + word.slice(1);
  });//from ww w  . j av  a2  s. c om
  words.forEach(function(word) {
    callback(word);
  });
}

Javascript String capitalize()

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/string/capitalize [rev. #2]

String.prototype.capitalize = function(){
  return this.replace(/\S+/g, function(a){
    return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
  });// w  w  w . j av  a 2 s. c  om
};

Javascript String capitalize()

var file = require('fs');

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

file.readFileSync(process.argv[2]).toString().split('\n').forEach(function(line) {
  var words = line.split(' ');
  var sentence = [];  
  for (i = 0; i < words.length; i++) {
    sentence.push(words[i].capitalize());
  }//from   w w  w  .  j a  v  a  2s  .  c om
  console.log(sentence.join(' '));
});

Javascript String capitalize()

/**/*from   w  w w .jav  a  2  s  . c o  m*/
 * Question: Capitalize fist letter in name.
 */


String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};

console.log('JANE'.capitalize());
console.log('john'.capitalize());

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this[0].toUpperCase() + this.substr(1, this.length-1);
};

String.prototype.titleize = function() {
  var res = [];//from   w ww.j  a va 2 s  .c o  m
  var parts = this.split(/_| /);
  $.each(parts, function(index, part) {
    res.push(part.capitalize());
  });
  return res.join(" ");
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this[0].toUpperCase() + this.slice(1)
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Array.prototype.capitalize = function() {
    return this.map(function(i) {
        return i.capitalize();
    })/*  w w  w  . j  ava2  s.  co  m*/
};

Javascript String capitalize()

String.prototype.capitalize = function(){
  var sa = this.replace(/-/g,' ');
  var saa = sa.toLowerCase();
  var sb = saa.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
  var sc = sb.replace(/\s+/g, '-');
  return sc;//from   w w  w.j av  a2 s  . c o m
};

Javascript String capitalize()

String.prototype.capitalize = function(){
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });/*from  w ww  . ja  va  2  s  . c  om*/
};

Javascript String capitalize()

/*/*from w  ww. j a v a 2  s  .  c o  m*/
 * Capitalize
 * http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
 */
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

module.exports = {}

Javascript String capitalize()

"use strict";//  ww w  .j  a va  2 s .  c o  m

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

/**/*from w ww. java2s  .co  m*/
Add a function like Python's capitalize to JavaScript strings.
*/
String.prototype.capitalize = function(){
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

// For capitalizing the first letter of a string
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

// Small prototype library for Online Notifier

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

"use strict";/*from   ww  w  . j  a  va2s.  c  o m*/

String.prototype.capitalize = function() {
 return this.charAt(0).toUpperCase() + this.slice(1);
};

module.exports = function(pageName) {
 return {
  title: pageName.capitalize(),
  url: pageName,
  id: pageName,
  visible: true
 };
};

Javascript String capitalize()

////from w w w . j  a  v a 2 s  .  c o m
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.toUpperCase()
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.replace(/^[a-z]/, function(m){ return m.toUpperCase(); })
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.setCharAt(0, this.charAt(0).toUpperCase());
};

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};


if(typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/, ''); 
    }/*  w  w  w.  ja va 2  s.c om*/
}

Javascript String capitalize()

// section: String.prototype
// desc: Methods added to all strings.

// func: capitalize()
// desc: returns a copy of the string with the first letter capitalized and the rest lowercase.
String.prototype.capitalize = function () {
 return this.substring(0,1).toUpperCase() + this.substring(1,this.length).toLowerCase();
};
// endsection//from  w ww.  jav  a  2s.  c om

Javascript String capitalize()

(function(){String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

String.prototype.clean = function() {
    str = this.replace(/'/g, '').replace(/\s/g, '').replace(/_/g, '');
    return str;/*from   w w  w.java  2 s.com*/
};

})();

Javascript String capitalize()

// Makes first letter uppercase
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function () {
  let splitString = this.split('')

  splitString.unshift(splitString.shift().toUpperCase())

  return splitString.join('')
}

Javascript String capitalize()

String.prototype.capitalize = function(){
  if(this.charCodeAt(0)<97)
      return this.toString();
  else//from  w  w  w .  ja v a  2s .c om
    return String.fromCharCode(this.charCodeAt(0)-32) + this.slice(1);
};

Javascript String capitalize()

/* best practice */

String.prototype.capitalize = function () {
  let c = this.charCodeAt(0)
  if (97 <= c && c <= 122) c -= 32
  
  return String.fromCharCode(c) + this.slice(1)
}

Javascript String capitalize()

/**//from   w w w . j  ava 2 s  .co  m
 * Capitalizes the first letter of a string and downcases all the others.
 *
 * @function external:String.prototype.capitalize
 * @return {string}
 * @example
 *  'hello'.capitalize() === 'Hello'
 *  'HELLO WORLD!'.capitalize() === 'Hello world!'
 */
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
};

Javascript String capitalize()

String.prototype.capitalize = function() {
    var t;//  ww w .j  a v a  2  s .  c o  m
    var capital = this;
    var cap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var low = 'abcdefghijklmnopqrstuvwxyz';
    for (var i=0;i<low.length;i++) {
        if (capital[0] === low[i]) {
            return t = cap[i] + capital.slice(1);
        }
        else t = capital;
    }
    return t;
}

console.log("the first character of this sentence is not a letter".capitalize());

// https://www.codewars.com/kata/capitalize-first-letter-of-a-string/discuss

Javascript String capitalize()

/*/*from www .  ja v a2 s  . c  o m*/
 String.capitalize()
 rog?o sampaio 2008, Jan 4
 
 Return:
  Capitalized string
  
 Sample:
  "I am the best and the girls love me!".capitalize() == "I Am The Best And The Girls Love Me!"
*/
String.prototype.capitalize = jCube.String.capitalize = function () {
 return this.charAt(0).toUpperCase() + this.substring(1).replace( /\s[a-z]/g, function(s){ return s.toUpperCase(); });
}

Javascript String capitalize()

/**//from www  .j  a  v  a 2 s  .c  o m
 *  String#capitalize() -> String
 *
 *  Capitalizes the first letter of a string and downcases all the others.
 *
 *  ##### Examples
 *
 *      'hello'.capitalize();
 *      // -> 'Hello'
 *
 *      'HELLO WORLD!'.capitalize();
 *      // -> 'Hello world!'
**/
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() +
    this.substring(1).toLowerCase();
};

Javascript String capitalize()

String.prototype.capitalize = function () {
   var obj = this;
   var newString = "";
   for (i in obj){ 
     newString += obj[i];//from  w  w  w  .j av  a  2 s.  c o m
     if (i == obj.length-1){
       break;
     }
   }
   if (newString[0].charCodeAt()>96&&newString[0].charCodeAt()<123) {
     var firstLetter = newString[0].charCodeAt();
     var newString = String.fromCharCode(firstLetter-32)+newString.substring(1,newString.length);
     return newString;
   } else {
     return newString;
   }
 }

Javascript String capitalize()

String.prototype.capitalize = function() {
    console.log(this.charAt(0));//from  w  w w  .j a v a  2s .c  om
    console.log(this.slice(1));
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

#!/usr/bin/js/*ww w.j av a2 s . c o m*/

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

function generateHashtag (str) {
 return (str.length > 140 || str.length < 1) ? false : "#" + str.split(" ").map(function(n){ return n.capitalize() }).join('');
}

//console.log('lorne'.capitalize());
console.log(generateHashtag(''));
console.log(generateHashtag('Lorne Greene'));
console.log(generateHashtag('tina turner'));

Javascript String capitalize()

String.prototype.capitalize = function() 
{
    return this.charAt(0).toUpperCase() + this.slice(1);
}

function thousandSeperate(x) 
{
 try/*from   w  w  w  .  j a va2 s  .  com*/
 {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
 }
 catch (err)
 {
  return x;
 }
}

function phoneSeperate(x) 
{
 try
 {
  return x.toString().replace(/\B(?=(\d{2})+(?!\d))/g, " ");
 }
 catch (err)
 {
  return x;
 }
}

function rnd(min,max)
{
 return Math.floor(Math.random()*(max-min+1)+min);
}

Javascript String capitalize()

////from   w w  w.  j  a v  a 2 s  .co m
// Prototype additions
//

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

var getCurrentDate = function() {
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!
    var yyyy = today.getFullYear();

    if(dd<10) {
        dd='0'+dd
    }//from w ww  .  j av a 2 s  .co  m

    if(mm<10) {
        mm='0'+mm
    }

    today = yyyy+'-'+mm+'-'+dd;
    return today;
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.replace(/([\s\-_]|^)./g, function (match) {
    return match.toUpperCase();
  });//from  w  w  w. j  a va  2 s.c  o m
}

Javascript String capitalize()

// STRING PROTOTYPE
String.prototype.capitalize = function() {
    return this.replace(/(^|\s)([a-z])/g, function(m, p1, p2) {
        return p1 + p2.toUpperCase();
    });/* w  w w .j  a v a  2 s .  c o  m*/
};

Javascript String capitalize()

String.prototype.capitalize = function capitalize() {
 return this[0].toUpperCase() + this.slice(1);
};

Javascript String capitalize()

// Add to standard prototypes
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

Javascript String capitalize()

/**// w  w w.  j  av a 2s  .  c  om
 * Capitalize a string.
 *
 * @return Capitalized string.
 */
String.prototype.capitalize = function () {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  sentence = this.split(' ');
  for(word in sentence) {
    sentence[word] = sentence[word].ucfirst();
  }/*from   w  w  w .j av  a  2  s  .c o  m*/
  return sentence.join(' ');
}

Javascript String capitalize()

/* $This file is distributed under the terms of the license in /doc/license.txt$ */

String.prototype.capitalize = function() {
    return this.substring(0,1).toUpperCase() + this.substring(1);
};

Javascript String capitalize()

/*/*  w w  w  .  j  a  v  a 2 s  .co m*/
 * @return {String} string with the first letter in upper case
 */
String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

/**//from www .j  a  v a2  s . c om
 * Capitalizes the first letter of a string and downcases all the others.
 *
 * @function module:String.prototype.capitalize
 * @return {string}
 * @example
 *  'hello'.capitalize() === 'Hello'
 *  'HELLO WORLD!'.capitalize() === 'Hello world!'
 */
String.prototype.capitalize = String.prototype.capitalize || function() {
    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
};

Javascript String capitalize()

/*// w w  w.ja v  a  2s .  c o  m
 * Objects extensions and support functions
 */

// We love Python capitalize()!
String.prototype.capitalize = function(){
    return this.replace(/^(.?)/, this.charAt(0).toUpperCase());
}

Javascript String capitalize()

/**//  www  . j a  v a  2s .co  m
 * @overview Extensions to existing JavaScript object.
 * @author Dave Huffman
 * @copyright 2014
 */

// Handle environments that don't provide a console.
if (typeof console === 'undefined') {
  console = {
    debug: function () {},
    dir:   function () {},
    info:  function () {},
    log:   function () {},
    warn:  function () {}
  };
}

/**
 * @returns {String} A capitalized version of this string.
 */
String.prototype.capitalize = function () {
  return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

function getRandomArbitaryInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

function getRandomSubArray (array) {
  if (array.length < 4) return false;
  var randomSubArray = [];
  _.each(array, function (elem, i) {
    if (Math.random() > 0.5) {
      randomSubArray.push(elem);//from   w  ww  . j  a  v  a 2  s  .c om
    }
  })
  return randomSubArray.length > 3 && randomSubArray.length < Math.ceil(array.length*0.5)  ? randomSubArray : getRandomSubArray(array);
}

function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
}

Javascript String capitalize()

// JavascriptExtensions.js
// Author: Bradley J. Spaulding
// Created On: 2011-02-12

String.prototype.capitalize = function() {
  return this[0].toUpperCase() + this.substring(1, this.length);
}

Javascript String capitalize()

String.prototype.capitalize = function() {
 return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};

String.prototype.toTitleCase = function() {
 var words = this.split(' ');
 var compiledString = '';

 for (var i = 0; i < words.length; i++) {
  compiledString += (' ' + words[i].capitalize());
 }

 compiledString = compiledString.slice(1);

 return compiledString;
};

function urlTitle(url) {
 var title = url.split('/').pop();

 title = title.replace(/-/gi, ' ');
 title = title.toTitleCase();/*from   w  ww  .  j  a v  a  2  s . c om*/

 return title;
}

// urlTitle('http://jdh11235.github.io/web-experiments/really-cool-experiment');
// => "Really Cool Experiment"

Javascript String capitalize()

// find and replace string. also, capitalize replacement if string getting replaced is also in caps
// http://www.freecodecamp.com/challenges/bonfire-search-and-replace

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

String.prototype.isUpperCased = function() {
    return this.charAt(0) === this.charAt(0).toUpperCase();
};

function replace(str, before, after) {
    var arr = str.split(' ');
    var sIdx = arr.indexOf(before);
    if (before.isUpperCased()) { after = after.capitalize(); }
    arr[sIdx] = after;/* w  w w  .  j  a v a2 s  .  c o  m*/
    console.log(arr.join(' '));
    return arr.join(' ');
}

replace("Let us go to the store", "store", "mall");

Javascript String capitalize()

String.prototype.capitalize = function() {
 if (this.length <= 1) return this;
 var words = this.split(" ");
 for (var i in words)
  if (words[i][0] && words[i][0].match(/[A-Za-z]/))
   words[i] = words[i].replace(new RegExp(words[i][0]),words[i][0].toUpperCase());
 return words.join(" ");
}

Javascript String capitalize()

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

function random(min, max){
 randomPart = Math.round((max - min) * Math.random());
 return randomPart + min;
}

function randomIn(array){
  var length = array.length - 1;
  return array[random(0, length)];
}

Javascript String capitalize()

// Capitalize a string
String.prototype.capitalize = function (){
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Javascript String capitalize()

"use strict";/*from w  ww. j a va2s . c  om*/

String.prototype.capitalize = function() {
  return this.toUpperCase();
};

String.prototype.dasherize = function() {
  return this.split("_").join("-");
};

String.prototype.times = function(amount) {
  // return [].range(1, amount).map(function(){
  //   return this;
  // }).join(" ");

  var i = 0, result = [];

  while(i < amount) {
    result.push(this);
    i++;
  }

  return result.join(" ");
};

String.prototype.blank = function() {
  var that = this.split("");
  return that.every(function(element) { return element === " "; }) || this === "";
};

console.log("hello".capitalize());
console.log("border_bottom_width".dasherize());
console.log("Nicole".times(5));
console.log("".blank());
console.log(" ".blank());
console.log("    ".blank());
console.log(" a".blank());



PreviousNext

Related