Capitalizes and Decapitalizes the string value. - Node.js String

Node.js examples for String:Case

Description

Capitalizes and Decapitalizes the string value.

Demo Code

// Hive Colony Framework
// Copyright (C) 2008-2015 Hive Solutions Lda.
///*from  www.  j av  a  2s .  c o  m*/
// This file is part of Hive Colony Framework.
//
// Hive Colony Framework is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Hive Colony Framework is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Hive Colony Framework. If not, see <http://www.gnu.org/licenses/>.

// __author__    = Jo?o Magalh?es <joamag@hive.pt>
// __version__   = 1.0.0
// __revision__  = $LastChangedRevision$
// __date__      = $LastChangedDate$
// __copyright__ = Copyright (c) 2008-2015 Hive Solutions Lda.
// __license__   = GNU General Public License (GPL), Version 3


/**
 * Capitalizes the string value.
 *
 * @return {String} The capitalized string.
 */
String.prototype.capitalize = function(local) {
    var f = function(a) {
        return a.charAt(0).toUpperCase() + a.substr(1);
    };

    return local
            ? f(this)
            : this.replace(/[\u00bf-\u1fff\u2c00-\uD7FF\w]+/g, f);
}

/**
 * Decapitalizes the string value.
 *
 * @return {String} The decapitalized string.
 */
String.prototype.decapitalize = function(local) {
    var f = function(a) {
        return a.charAt(0).toLowerCase() + a.substr(1);
    };

    return local
            ? f(this)
            : this.replace(/[\u00bf-\u1fff\u2c00-\uD7FF\w]+/g, f);
}

Related Tutorials