📄 string.js
字号:
String.prototype.unescapeHTML = function() { return this.replace(/&/gm, "&") .replace(/</gm, "<") .replace(/>/gm, ">"); //.replace(/"/gm, '"') //.replace(/'/gm, "'"); } /** * Returns whether the string starts with the specified string paramerter. * @param {String} _string * @return {Boolean} */ String.prototype.startsWith = function(_string) { return this.indexOf(_string) == 0; } /** * Returns whether the string ends with the specified string paramerter. * @param {String} _string * @return {Boolean} */ String.prototype.endsWith = function(_string) { return this.lastIndexOf(_string) == (this.length - _string.length); } /** * Returns whether the string has the specified string paramerter within it's contents. * @param {String} _string * @return {Boolean} */ String.prototype.has = function(_char) { return this.indexOf(_char) > -1; } /** * Returns a new string but in reverse order from the original string. * @return {String} */ String.prototype.reverse = function() { return this.split("").reverse().join(""); } /** * Truncates the string to the specified length. Returns a new string. * @param {Number} _length The length to truncate the string to. * @return {String} */ String.prototype.truncate = function(_length) { return this.slice(0, _length); } /** * Returns a new string capitalizing the original string. * @return {String} */ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); } /** * Returns a new string camel casing the original hyphen or snake case string. Ex. background-image or background_image -> backgroundImage. * @return {String} */ String.prototype.camelCase = function() { var _camelized = ""; var me = this; var _once = false; if(this.indexOf("-")>-1) { this.each("-", function(_value, _index) { if(!_value) me.$continue(); if(!_once) { _camelized += _value.charAt(0).toLowerCase() + _value.substring(1); _once = true; } else { _camelized += _value.charAt(0).toUpperCase() + _value.substring(1); } }); } else if(this.indexOf("_")>-1) { this.each("_", function(_value, _index) { if(!_value) me.$continue(); if(!_once) { _camelized += _value.charAt(0).toLowerCase() + _value.substring(1); _once = true; } else { _camelized += _value.charAt(0).toUpperCase() + _value.substring(1); } }); } else { _camelized = this; } return _camelized; } /** * Returns a new string hyphen casing the original camel case string. Ex. backgroundImage -> background-image. * @return {String} */ String.prototype.hyphenCase = function() { var me = this; var _hyphenated = ""; this.each("", function(_value, _index) { if(_index == 0 && _value.isUpperCase()) { _hyphenated += _value.toLowerCase(); } else if(_value.isUpperCase()) { _hyphenated += "-"; _hyphenated += _value.toLowerCase(); } else { _hyphenated += _value; } }); return _hyphenated; } /** * Returns a new string snake casing the original camel case string. Ex. backgroundImage -> background_image. * @return {String} */ String.prototype.snakeCase = function() { var me = this; var _snaked = ""; this.each("", function(_value, _index) { if(_index == 0 && _value.isUpperCase()) { _snaked += _value.toLowerCase(); } else if(_value.isUpperCase()) { _snaked += "_"; _snaked += _value.toLowerCase(); } else { _snaked += _value; } }); return _snaked; } /** * Returns whether the string has all up cased characters. * @return {Boolean} */ String.prototype.isUpperCase = function() { var me = this; var _upper = true; this.each("", function(_value) { if(([" ", "\n", "\t", "\r"].indexOf(_value) == -1) && (_value.equals(_value.toLowerCase()))) { _upper = false; me.$break(); } }); return _upper; } /** * Returns whether the string has all lower cased characters. * @return {Boolean} */ String.prototype.isLowerCase = function() { var me = this; var _lower = true; this.each("", function(_value) { if(([" ", "\n", "\t", "\r"].indexOf(_value) == -1) && (_value.equals(_value.toUpperCase()))) { _lower = false; me.$break(); } }); return _lower; } /** * Returns whether the string is blank. Space, tab, new line, carriage return are consider empty. * @return {Boolean} */ String.prototype.isBlank = function() { if(this.isEmpty()) return true; var _blank = true; var me = this; this.each("", function(_value) { if ((!" ".equals(_value)) && (!"\t".equals(_value)) && (!"\n".equals(_value)) && (!"\r".equals(_value))) { _blank = false; me.$break(); } }); return _blank; } /** * Returns whether the string is empty, where this.length == 0. * @return {Boolean} */ String.prototype.isEmpty = function() { return this.length == 0; }String.prototype.invoke = jsx.collections.Enumerable.invoke;String.prototype.map = jsx.collections.Enumerable.map;String.prototype.detect = jsx.collections.Enumerable.detect;String.prototype.echo = jsx.collections.Enumerable.echo;String.prototype.zip = jsx.collections.Enumerable.zip;String.prototype.max = jsx.collections.Enumerable.max;String.prototype.toArray = jsx.collections.Enumerable.toArray;String.prototype.min = jsx.collections.Enumerable.min;String.prototype.convertToArray = jsx.collections.Enumerable.convertToArray;String.prototype.$break = jsx.collections.Enumerable.$break;String.prototype.sortBy = jsx.collections.Enumerable.sortBy;String.prototype.select = jsx.collections.Enumerable.select;String.prototype.inject = jsx.collections.Enumerable.inject;String.prototype.find = jsx.collections.Enumerable.find;String.prototype.collect = jsx.collections.Enumerable.collect;String.prototype.any = jsx.collections.Enumerable.any;String.prototype.entries = jsx.collections.Enumerable.entries;String.prototype.findAll = jsx.collections.Enumerable.findAll;String.prototype.grep = jsx.collections.Enumerable.grep;String.prototype.pluck = jsx.collections.Enumerable.pluck;String.prototype.$continue = jsx.collections.Enumerable.$continue;String.prototype.partition = jsx.collections.Enumerable.partition;String.prototype.reject = jsx.collections.Enumerable.reject;String.prototype.all = jsx.collections.Enumerable.all;String.prototype.member = jsx.collections.Enumerable.member;String.prototype.include = jsx.collections.Enumerable.include;String.PACKAGE = "";String.CLASS = "String";String.SUPER_CLASS = "";String.IMPORTS = ["jsx.collections.Enumerable"];String.INTERFACES = [];String.MIXINS = ["jsx.collections.Enumerable"];String.getName = function(){return String.CLASS;}String.klass = new jsx.lang.Class(String.getName());String.prototype.getClass = function(){return String.klass;}String.WARNINGS = [];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -