lettuce
Version:
Lettuce JS, Mini Mobile Framework for Romantic with DSL.
99 lines (89 loc) • 2.61 kB
JavaScript
/**
* MelonJS Game Engine
* (C) 2011 - 2014 Olivier Biot, Jason Oster, Aaron McLeod
* http://www.melonjs.org
*/
/**
* The built in String Object
* @external String
* @see {@link https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String|String}
*/
if (!String.prototype.trim) {
/**
* returns the string stripped of whitespace from both ends
* @memberof! external:String#
* @alias trim
* @return {string} trimmed string
*/
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/gm, "");
};
}
if (!String.prototype.trimLeft) {
/**
* returns the string stripped of whitespace from the left.
* @memberof! external:String#
* @alias trimLeft
* @return {string} trimmed string
*/
String.prototype.trimLeft = function () {
return this.replace(/^\s+/, "");
};
}
if (!String.prototype.trimRight) {
/**
* returns the string stripped of whitespace from the right.
* @memberof! external:String#
* @alias trimRight
* @return {string} trimmed string
*/
String.prototype.trimRight = function () {
return this.replace(/\s+$/, "");
};
}
/**
* add isNumeric fn to the string object
* @memberof! external:String#
* @alias isNumeric
* @return {boolean} true if string contains only digits
*/
String.prototype.isNumeric = function () {
return (!isNaN(this) && this.trim() !== "");
};
/**
* add a isBoolean fn to the string object
* @memberof! external:String#
* @alias isBoolean
* @return {boolean} true if the string is either true or false
*/
String.prototype.isBoolean = function () {
var trimmed = this.trim();
return ("true" === trimmed) || ("false" === trimmed);
};
if (!String.prototype.contains) {
/**
* determines whether or not a string contains another string.
* @memberof! external:String#
* @alias contains
* @param {string} str A string to be searched for within this string.
* @param {number} [startIndex=0] The position in this string at which
* to begin searching for given string.
* @return {boolean} true if contains the specified string
*/
String.prototype.contains = function (str, startIndex) {
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
};
}
/**
* convert the string to hex value
* @memberof! external:String#
* @alias toHex
* @return {string}
*/
String.prototype.toHex = function () {
var res = "", c = 0;
while (c < this.length) {
res += this.charCodeAt(c++).toString(16);
}
return res;
};