c9-core/node_modules/c9/string.js

47 wiersze
1015 B
JavaScript

define(function(require, exports, module) {
"use strict";
/*
* Casts the first character in a string to uppercase.
*
* @param {String} str
* @type {String}
*/
exports.uCaseFirst = function(str) {
return str.substr(0, 1).toUpperCase() + str.substr(1);
};
/*
* Removes spaces and other space-like characters from the left and right ends
* of a string
*
* @param {String} str
* @type {String}
*/
exports.trim = function(str) {
return str.replace(/[\s\n\r]*$/, "").replace(/^[\s\n\r]*/, "");
};
/*
* Concatenate a string with itself n-times.
*
* @param {String} str
* @param {Number} times Number of times to repeat the String concatenation
* @type {String}
*/
exports.repeat = function(str, times) {
return new Array(times + 1).join(str);
};
/*
* Count the number of occurences of substring 'str' inside a string
*
* @param {String} str
* @param {String} substr
* @type {Number}
*/
exports.count = function(str, substr){
return str.split(substr).length - 1;
};
});