Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,9 @@ | ||
1.2.0 / 2013-01-15 | ||
------------------ | ||
* Added AMD support. | ||
* Fixed replaceAll bug. #21 | ||
* Changed `slugify` behavior. #17 | ||
* Renamed `decodeHtmlEntities` to `decodeHTMLEntities` for consistency. `decodeHtmlEntities` is deprecated. #23 | ||
1.1.0 / 2012-10-08 | ||
@@ -2,0 +10,0 @@ ------------------ |
@@ -5,3 +5,3 @@ { | ||
"description": "string contains methods that aren't included in the vanilla JavaScript string such as escaping HTML, decoding HTML entities, stripping tags, etc.", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "string", |
@@ -22,3 +22,3 @@ /* | ||
var VERSION = '1.1.0'; | ||
var VERSION = '1.2.0'; | ||
@@ -110,7 +110,7 @@ function S(s) { | ||
isAlpha: function() { | ||
return !/[^a-zA-Z]/.test(this.s); | ||
return !/[^a-z\xC0-\xFF]/.test(this.s.toLowerCase()); | ||
}, | ||
isAlphaNumeric: function() { | ||
return !/[^a-zA-Z0-9]/.test(this.s); | ||
return !/[^0-9a-z\xC0-\xFF]/.test(this.s.toLowerCase()); | ||
}, | ||
@@ -123,3 +123,3 @@ | ||
isLower: function() { | ||
return !/[^a-z]/.test(this.s); | ||
return this.isAlpha() && this.s.toLowerCase() === this.s; | ||
}, | ||
@@ -132,3 +132,3 @@ | ||
isUpper: function() { | ||
return !/[^A-Z]/.test(this.s); | ||
return this.isAlpha() && this.s.toUpperCase() === this.s; | ||
}, | ||
@@ -225,3 +225,4 @@ | ||
replaceAll: function(ss, r) { | ||
var s = this.s.replace(new RegExp(ss, 'g'), r); | ||
//var s = this.s.replace(new RegExp(ss, 'g'), r); | ||
var s = this.s.split(ss).join(r) | ||
return new S(s); | ||
@@ -240,3 +241,3 @@ }, | ||
slugify: function() { | ||
var sl = (new S(this.s.replace(/[^\w\s-]/g, ''))).dasherize().s; | ||
var sl = (new S(this.s.replace(/[^\w\s-]/g, '').toLowerCase())).dasherize().s; | ||
if (sl.charAt(0) === '-') | ||
@@ -485,2 +486,3 @@ sl = sl.substr(1); | ||
__sp.toBool = __sp.toBoolean; | ||
__sp.decodeHTMLEntities = __sp.decodeHtmlEntities //ensure consistent casing scheme of 'HTML' | ||
@@ -546,6 +548,13 @@ | ||
} else { | ||
window.S = wrap; | ||
window.S.extendPrototype = extendPrototype; | ||
window.S.restorePrototype = restorePrototype; | ||
window.S.VERSION = VERSION; | ||
if(typeof define === "function" && define.amd) { | ||
define([], function() { | ||
return wrap; | ||
}); | ||
} else { | ||
window.S = wrap; | ||
window.S.extendPrototype = extendPrototype; | ||
window.S.restorePrototype = restorePrototype; | ||
window.S.VERSION = VERSION; | ||
} | ||
} | ||
@@ -552,0 +561,0 @@ |
@@ -17,2 +17,2 @@ /* | ||
DEALINGS IN THE SOFTWARE. | ||
*/(function(){"use strict";function t(e){e!==null&&e!==undefined?typeof e=="string"?this.s=e:this.s=e.toString():this.s=e,this.orig=e,e!==null&&e!==undefined?this.__defineGetter__?this.__defineGetter__("length",function(){return this.s.length}):this.length=e.length:this.length=-1}function s(){for(var e in r)(function(e){var t=r[e];n.hasOwnProperty(e)||(i.push(e),n[e]=function(){return String.prototype.s=this,t.apply(this,arguments)})})(e)}function o(){for(var e=0;e<i.length;++e)delete String.prototype[i[e]];i.length=0}function f(){var e=l(),t={};for(var r=0;r<e.length;++r){var i=e[r],s=n[i];try{var o=typeof s.apply("teststring",[]);t[i]=o}catch(u){}}return t}function l(){var e=[];if(Object.getOwnPropertyNames)return e=Object.getOwnPropertyNames(n),e.splice(e.indexOf("valueOf"),1),e.splice(e.indexOf("toString"),1),e;var t={},r=[];for(var i in String.prototype)t[i]=i;for(var i in Object.prototype)delete t[i];for(var i in t)e.push(i);return e}function c(e){return new t(e)}function h(e,t){var n=[],r;for(r=0;r<e.length;r++)n.push(e[r]),t&&t.call(e,e[r],r);return n}function m(e,t){var n={},r={},i,s={},o={},u={},a={};s[0]="HTML_SPECIALCHARS",s[1]="HTML_ENTITIES",o[0]="ENT_NOQUOTES",o[2]="ENT_COMPAT",o[3]="ENT_QUOTES",u=isNaN(e)?e?e.toUpperCase():"HTML_SPECIALCHARS":s[e],a=isNaN(t)?t?t.toUpperCase():"ENT_COMPAT":o[t];if(u!=="HTML_SPECIALCHARS"&&u!=="HTML_ENTITIES")throw new Error("Table: "+u+" not supported");n[38]="&",u==="HTML_ENTITIES"&&(n[160]=" ",n[161]="¡",n[162]="¢",n[163]="£",n[164]="¤",n[165]="¥",n[166]="¦",n[167]="§",n[168]="¨",n[169]="©",n[170]="ª",n[171]="«",n[172]="¬",n[173]="­",n[174]="®",n[175]="¯",n[176]="°",n[177]="±",n[178]="²",n[179]="³",n[180]="´",n[181]="µ",n[182]="¶",n[183]="·",n[184]="¸",n[185]="¹",n[186]="º",n[187]="»",n[188]="¼",n[189]="½",n[190]="¾",n[191]="¿",n[192]="À",n[193]="Á",n[194]="Â",n[195]="Ã",n[196]="Ä",n[197]="Å",n[198]="Æ",n[199]="Ç",n[200]="È",n[201]="É",n[202]="Ê",n[203]="Ë",n[204]="Ì",n[205]="Í",n[206]="Î",n[207]="Ï",n[208]="Ð",n[209]="Ñ",n[210]="Ò",n[211]="Ó",n[212]="Ô",n[213]="Õ",n[214]="Ö",n[215]="×",n[216]="Ø",n[217]="Ù",n[218]="Ú",n[219]="Û",n[220]="Ü",n[221]="Ý",n[222]="Þ",n[223]="ß",n[224]="à",n[225]="á",n[226]="â",n[227]="ã",n[228]="ä",n[229]="å",n[230]="æ",n[231]="ç",n[232]="è",n[233]="é",n[234]="ê",n[235]="ë",n[236]="ì",n[237]="í",n[238]="î",n[239]="ï",n[240]="ð",n[241]="ñ",n[242]="ò",n[243]="ó",n[244]="ô",n[245]="õ",n[246]="ö",n[247]="÷",n[248]="ø",n[249]="ù",n[250]="ú",n[251]="û",n[252]="ü",n[253]="ý",n[254]="þ",n[255]="ÿ"),a!=="ENT_NOQUOTES"&&(n[34]="""),a==="ENT_QUOTES"&&(n[39]="'"),n[60]="<",n[62]=">";for(i in n)n.hasOwnProperty(i)&&(r[String.fromCharCode(i)]=n[i]);return r}var e="1.1.0",n=String.prototype,r=t.prototype={camelize:function(){var e=this.trim().s.replace(/(\-|_|\s)+(.)?/g,function(e,t,n){return n?n.toUpperCase():""});return new t(e)},capitalize:function(){return new t(this.s.substr(0,1).toUpperCase()+this.s.substring(1).toLowerCase())},charAt:function(e){return this.s.charAt(e)},collapseWhitespace:function(){var e=this.s.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,"");return new t(e)},contains:function(e){return this.s.indexOf(e)>=0},dasherize:function(){var e=this.trim().s.replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase();return new t(e)},decodeHtmlEntities:function(e){var n="",r="",i={},s=this.s;if(!1===(i=m("HTML_ENTITIES",e)))return!1;delete i["&"],i["&"]="&";for(n in i)r=i[n],s=s.split(r).join(n);return s=s.split("'").join("'"),new t(s)},endsWith:function(e){var t=this.s.length-e.length;return t>=0&&this.s.indexOf(e,t)===t},escapeHTML:function(){return new t(this.s.replace(/[&<>"']/g,function(e){return"&"+d[e]+";"}))},isAlpha:function(){return!/[^a-zA-Z]/.test(this.s)},isAlphaNumeric:function(){return!/[^a-zA-Z0-9]/.test(this.s)},isEmpty:function(){return this.s===null||this.s===undefined?!0:/^[\s\xa0]*$/.test(this.s)},isLower:function(){return!/[^a-z]/.test(this.s)},isNumeric:function(){return!/[^0-9]/.test(this.s)},isUpper:function(){return!/[^A-Z]/.test(this.s)},left:function(e){if(e>=0){var n=this.s.substr(0,e);return new t(n)}return this.right(-e)},lines:function(){var e=this.s.split("\n");for(var t=0;t<e.length;++t)e[t]=e[t].replace(/(^\s*|\s*$)/g,"");return e},pad:function(e,n){n=n||" ";if(this.s.length>=e)return new t(this.s);e-=this.s.length;var r=Array(Math.ceil(e/2)+1).join(n),i=Array(Math.floor(e/2)+1).join(n);return new t(r+this.s+i)},padLeft:function(e,n){return n=n||" ",this.s.length>=e?new t(this.s):new t(Array(e-this.s.length+1).join(n)+this.s)},padRight:function(e,n){return n=n||" ",this.s.length>=e?new t(this.s):new t(this.s+Array(e-this.s.length+1).join(n))},parseCSV:function(e,t){e=e||",",escape="\\",typeof t=="undefined"&&(t='"');var n=0,r=[],i=[],s=this.s.length,o=!1,u=this,a=function(e){return u.s.charAt(e)};t||(o=!0);while(n<s){var f=a(n);switch(f){case t:o?a(n-1)===escape?r.push(f):o=!1:o=!0;break;case e:o&&t?r.push(f):(i.push(r.join("")),r.length=0);break;case escape:t&&a(n+1)!==t&&r.push(f);break;default:o&&r.push(f)}n+=1}return i.push(r.join("")),i},replaceAll:function(e,n){var r=this.s.replace(new RegExp(e,"g"),n);return new t(r)},right:function(e){if(e>=0){var n=this.s.substr(this.s.length-e,e);return new t(n)}return this.left(-e)},slugify:function(){var e=(new t(this.s.replace(/[^\w\s-]/g,""))).dasherize().s;return e.charAt(0)==="-"&&(e=e.substr(1)),new t(e)},startsWith:function(e){return this.s.lastIndexOf(e,0)===0},stripPunctuation:function(){return new t(this.s.replace(/[^\w\s]|_/g,"").replace(/\s+/g," "))},stripTags:function(){var e=this.s,n=arguments.length>0?arguments:[""];return h(n,function(t){e=e.replace(RegExp("</?"+t+"[^<>]*>","gi"),"")}),new t(e)},times:function(e){return new t((new Array(e+1)).join(this.s))},toBoolean:function(){if(typeof this.orig=="string"){var e=this.s.toLowerCase();return e==="true"||e==="yes"||e==="on"}return this.orig===!0||this.orig===1},toFloat:function(e){var t=parseFloat(this.s,10);return e?parseFloat(t.toFixed(e)):t},toInt:function(){return/^\s*-?0x/i.test(this.s)?parseInt(this.s,16):parseInt(this.s,10)},trim:function(){var e;return typeof String.prototype.trim=="undefined"?e=this.s.replace(/(^\s*|\s*$)/g,""):e=this.s.trim(),new t(e)},trimLeft:function(){var e;return n.trimLeft?e=this.s.trimLeft():e=this.s.replace(/(^\s*)/g,""),new t(e)},trimRight:function(){var e;return n.trimRight?e=this.s.trimRight():e=this.s.replace(/\s+$/,""),new t(e)},truncate:function(e,n){var r=this.s;e=~~e,n=n||"...";if(r.length<=e)return r;var i=function(e){return e.toUpperCase()!==e.toLowerCase()?"A":" "},s=r.slice(0,e+1).replace(/.(?=\W*\w*$)/g,i);return s.slice(s.length-2).match(/\w\w/)?s=s.replace(/\s*\S+$/,""):s=(new t(s.slice(0,s.length-1))).trimRight().s,(s+n).length>r.length?new t(r):new t(r.slice(0,s.length)+n)},toCSV:function(){function u(e){return e!==null&&e!==""}var e=",",n='"',r="\\",i=!0,s=!1,o=[];typeof arguments[0]=="object"?(e=arguments[0].delimiter||e,e=arguments[0].separator||e,n=arguments[0].qualifier||n,i=!!arguments[0].encloseNumbers,r=arguments[0].escapeChar||r,s=!!arguments[0].keys):typeof arguments[0]=="string"&&(e=arguments[0]),typeof arguments[1]=="string"&&(n=arguments[1]),arguments[1]===null&&(n=null);if(this.orig instanceof Array)o=this.orig;else for(var a in this.orig)this.orig.hasOwnProperty(a)&&(s?o.push(a):o.push(this.orig[a]));var f=r+n,l=[];for(var c=0;c<o.length;++c){var h=u(n);typeof o[c]=="number"&&(h&=i),h&&l.push(n);var p=(new t(o[c])).replaceAll(n,f).s;l.push(p),h&&l.push(n),e&&l.push(e)}return l.length=l.length-1,new t(l.join(""))},toString:function(){return this.s},underscore:function(){var e=this.trim().s.replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase();return(new t(this.s.charAt(0))).isUpper()&&(e="_"+e),new t(e)},unescapeHTML:function(){return new t(this.s.replace(/\&([^;]+);/g,function(e,t){var n;return t in p?p[t]:(n=t.match(/^#x([\da-fA-F]+)$/))?String.fromCharCode(parseInt(n[1],16)):(n=t.match(/^#(\d+)$/))?String.fromCharCode(~~n[1]):e}))},valueOf:function(){return this.s.valueOf()}},i=[],u=f();for(var a in u)(function(e){var i=n[e];typeof i=="function"&&(r[e]||(u[e]==="string"?r[e]=function(){return new t(i.apply(this,arguments))}:r[e]=i))})(a);r.repeat=r.times,r.include=r.contains,r.toInteger=r.toInt,r.toBool=r.toBoolean,typeof module!="undefined"&&typeof module.exports!="undefined"?(module.exports=c,module.exports.extendPrototype=s,module.exports.restorePrototype=o,module.exports.VERSION=e):(window.S=c,window.S.extendPrototype=s,window.S.restorePrototype=o,window.S.VERSION=e);var p={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"},d={};for(var v in p)d[p[v]]=v}).call(this); | ||
*/(function(){"use strict";function t(e){e!==null&&e!==undefined?typeof e=="string"?this.s=e:this.s=e.toString():this.s=e,this.orig=e,e!==null&&e!==undefined?this.__defineGetter__?this.__defineGetter__("length",function(){return this.s.length}):this.length=e.length:this.length=-1}function s(){for(var e in r)(function(e){var t=r[e];n.hasOwnProperty(e)||(i.push(e),n[e]=function(){return String.prototype.s=this,t.apply(this,arguments)})})(e)}function o(){for(var e=0;e<i.length;++e)delete String.prototype[i[e]];i.length=0}function f(){var e=l(),t={};for(var r=0;r<e.length;++r){var i=e[r],s=n[i];try{var o=typeof s.apply("teststring",[]);t[i]=o}catch(u){}}return t}function l(){var e=[];if(Object.getOwnPropertyNames)return e=Object.getOwnPropertyNames(n),e.splice(e.indexOf("valueOf"),1),e.splice(e.indexOf("toString"),1),e;var t={},r=[];for(var i in String.prototype)t[i]=i;for(var i in Object.prototype)delete t[i];for(var i in t)e.push(i);return e}function c(e){return new t(e)}function h(e,t){var n=[],r;for(r=0;r<e.length;r++)n.push(e[r]),t&&t.call(e,e[r],r);return n}function m(e,t){var n={},r={},i,s={},o={},u={},a={};s[0]="HTML_SPECIALCHARS",s[1]="HTML_ENTITIES",o[0]="ENT_NOQUOTES",o[2]="ENT_COMPAT",o[3]="ENT_QUOTES",u=isNaN(e)?e?e.toUpperCase():"HTML_SPECIALCHARS":s[e],a=isNaN(t)?t?t.toUpperCase():"ENT_COMPAT":o[t];if(u!=="HTML_SPECIALCHARS"&&u!=="HTML_ENTITIES")throw new Error("Table: "+u+" not supported");n[38]="&",u==="HTML_ENTITIES"&&(n[160]=" ",n[161]="¡",n[162]="¢",n[163]="£",n[164]="¤",n[165]="¥",n[166]="¦",n[167]="§",n[168]="¨",n[169]="©",n[170]="ª",n[171]="«",n[172]="¬",n[173]="­",n[174]="®",n[175]="¯",n[176]="°",n[177]="±",n[178]="²",n[179]="³",n[180]="´",n[181]="µ",n[182]="¶",n[183]="·",n[184]="¸",n[185]="¹",n[186]="º",n[187]="»",n[188]="¼",n[189]="½",n[190]="¾",n[191]="¿",n[192]="À",n[193]="Á",n[194]="Â",n[195]="Ã",n[196]="Ä",n[197]="Å",n[198]="Æ",n[199]="Ç",n[200]="È",n[201]="É",n[202]="Ê",n[203]="Ë",n[204]="Ì",n[205]="Í",n[206]="Î",n[207]="Ï",n[208]="Ð",n[209]="Ñ",n[210]="Ò",n[211]="Ó",n[212]="Ô",n[213]="Õ",n[214]="Ö",n[215]="×",n[216]="Ø",n[217]="Ù",n[218]="Ú",n[219]="Û",n[220]="Ü",n[221]="Ý",n[222]="Þ",n[223]="ß",n[224]="à",n[225]="á",n[226]="â",n[227]="ã",n[228]="ä",n[229]="å",n[230]="æ",n[231]="ç",n[232]="è",n[233]="é",n[234]="ê",n[235]="ë",n[236]="ì",n[237]="í",n[238]="î",n[239]="ï",n[240]="ð",n[241]="ñ",n[242]="ò",n[243]="ó",n[244]="ô",n[245]="õ",n[246]="ö",n[247]="÷",n[248]="ø",n[249]="ù",n[250]="ú",n[251]="û",n[252]="ü",n[253]="ý",n[254]="þ",n[255]="ÿ"),a!=="ENT_NOQUOTES"&&(n[34]="""),a==="ENT_QUOTES"&&(n[39]="'"),n[60]="<",n[62]=">";for(i in n)n.hasOwnProperty(i)&&(r[String.fromCharCode(i)]=n[i]);return r}var e="1.2.0",n=String.prototype,r=t.prototype={camelize:function(){var e=this.trim().s.replace(/(\-|_|\s)+(.)?/g,function(e,t,n){return n?n.toUpperCase():""});return new t(e)},capitalize:function(){return new t(this.s.substr(0,1).toUpperCase()+this.s.substring(1).toLowerCase())},charAt:function(e){return this.s.charAt(e)},collapseWhitespace:function(){var e=this.s.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,"");return new t(e)},contains:function(e){return this.s.indexOf(e)>=0},dasherize:function(){var e=this.trim().s.replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase();return new t(e)},decodeHtmlEntities:function(e){var n="",r="",i={},s=this.s;if(!1===(i=m("HTML_ENTITIES",e)))return!1;delete i["&"],i["&"]="&";for(n in i)r=i[n],s=s.split(r).join(n);return s=s.split("'").join("'"),new t(s)},endsWith:function(e){var t=this.s.length-e.length;return t>=0&&this.s.indexOf(e,t)===t},escapeHTML:function(){return new t(this.s.replace(/[&<>"']/g,function(e){return"&"+d[e]+";"}))},isAlpha:function(){return!/[^a-z\xC0-\xFF]/.test(this.s.toLowerCase())},isAlphaNumeric:function(){return!/[^0-9a-z\xC0-\xFF]/.test(this.s.toLowerCase())},isEmpty:function(){return this.s===null||this.s===undefined?!0:/^[\s\xa0]*$/.test(this.s)},isLower:function(){return this.isAlpha()&&this.s.toLowerCase()===this.s},isNumeric:function(){return!/[^0-9]/.test(this.s)},isUpper:function(){return this.isAlpha()&&this.s.toUpperCase()===this.s},left:function(e){if(e>=0){var n=this.s.substr(0,e);return new t(n)}return this.right(-e)},lines:function(){var e=this.s.split("\n");for(var t=0;t<e.length;++t)e[t]=e[t].replace(/(^\s*|\s*$)/g,"");return e},pad:function(e,n){n=n||" ";if(this.s.length>=e)return new t(this.s);e-=this.s.length;var r=Array(Math.ceil(e/2)+1).join(n),i=Array(Math.floor(e/2)+1).join(n);return new t(r+this.s+i)},padLeft:function(e,n){return n=n||" ",this.s.length>=e?new t(this.s):new t(Array(e-this.s.length+1).join(n)+this.s)},padRight:function(e,n){return n=n||" ",this.s.length>=e?new t(this.s):new t(this.s+Array(e-this.s.length+1).join(n))},parseCSV:function(e,t){e=e||",",escape="\\",typeof t=="undefined"&&(t='"');var n=0,r=[],i=[],s=this.s.length,o=!1,u=this,a=function(e){return u.s.charAt(e)};t||(o=!0);while(n<s){var f=a(n);switch(f){case t:o?a(n-1)===escape?r.push(f):o=!1:o=!0;break;case e:o&&t?r.push(f):(i.push(r.join("")),r.length=0);break;case escape:t&&a(n+1)!==t&&r.push(f);break;default:o&&r.push(f)}n+=1}return i.push(r.join("")),i},replaceAll:function(e,n){var r=this.s.split(e).join(n);return new t(r)},right:function(e){if(e>=0){var n=this.s.substr(this.s.length-e,e);return new t(n)}return this.left(-e)},slugify:function(){var e=(new t(this.s.replace(/[^\w\s-]/g,"").toLowerCase())).dasherize().s;return e.charAt(0)==="-"&&(e=e.substr(1)),new t(e)},startsWith:function(e){return this.s.lastIndexOf(e,0)===0},stripPunctuation:function(){return new t(this.s.replace(/[^\w\s]|_/g,"").replace(/\s+/g," "))},stripTags:function(){var e=this.s,n=arguments.length>0?arguments:[""];return h(n,function(t){e=e.replace(RegExp("</?"+t+"[^<>]*>","gi"),"")}),new t(e)},times:function(e){return new t((new Array(e+1)).join(this.s))},toBoolean:function(){if(typeof this.orig=="string"){var e=this.s.toLowerCase();return e==="true"||e==="yes"||e==="on"}return this.orig===!0||this.orig===1},toFloat:function(e){var t=parseFloat(this.s,10);return e?parseFloat(t.toFixed(e)):t},toInt:function(){return/^\s*-?0x/i.test(this.s)?parseInt(this.s,16):parseInt(this.s,10)},trim:function(){var e;return typeof String.prototype.trim=="undefined"?e=this.s.replace(/(^\s*|\s*$)/g,""):e=this.s.trim(),new t(e)},trimLeft:function(){var e;return n.trimLeft?e=this.s.trimLeft():e=this.s.replace(/(^\s*)/g,""),new t(e)},trimRight:function(){var e;return n.trimRight?e=this.s.trimRight():e=this.s.replace(/\s+$/,""),new t(e)},truncate:function(e,n){var r=this.s;e=~~e,n=n||"...";if(r.length<=e)return r;var i=function(e){return e.toUpperCase()!==e.toLowerCase()?"A":" "},s=r.slice(0,e+1).replace(/.(?=\W*\w*$)/g,i);return s.slice(s.length-2).match(/\w\w/)?s=s.replace(/\s*\S+$/,""):s=(new t(s.slice(0,s.length-1))).trimRight().s,(s+n).length>r.length?new t(r):new t(r.slice(0,s.length)+n)},toCSV:function(){function u(e){return e!==null&&e!==""}var e=",",n='"',r="\\",i=!0,s=!1,o=[];typeof arguments[0]=="object"?(e=arguments[0].delimiter||e,e=arguments[0].separator||e,n=arguments[0].qualifier||n,i=!!arguments[0].encloseNumbers,r=arguments[0].escapeChar||r,s=!!arguments[0].keys):typeof arguments[0]=="string"&&(e=arguments[0]),typeof arguments[1]=="string"&&(n=arguments[1]),arguments[1]===null&&(n=null);if(this.orig instanceof Array)o=this.orig;else for(var a in this.orig)this.orig.hasOwnProperty(a)&&(s?o.push(a):o.push(this.orig[a]));var f=r+n,l=[];for(var c=0;c<o.length;++c){var h=u(n);typeof o[c]=="number"&&(h&=i),h&&l.push(n);var p=(new t(o[c])).replaceAll(n,f).s;l.push(p),h&&l.push(n),e&&l.push(e)}return l.length=l.length-1,new t(l.join(""))},toString:function(){return this.s},underscore:function(){var e=this.trim().s.replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase();return(new t(this.s.charAt(0))).isUpper()&&(e="_"+e),new t(e)},unescapeHTML:function(){return new t(this.s.replace(/\&([^;]+);/g,function(e,t){var n;return t in p?p[t]:(n=t.match(/^#x([\da-fA-F]+)$/))?String.fromCharCode(parseInt(n[1],16)):(n=t.match(/^#(\d+)$/))?String.fromCharCode(~~n[1]):e}))},valueOf:function(){return this.s.valueOf()}},i=[],u=f();for(var a in u)(function(e){var i=n[e];typeof i=="function"&&(r[e]||(u[e]==="string"?r[e]=function(){return new t(i.apply(this,arguments))}:r[e]=i))})(a);r.repeat=r.times,r.include=r.contains,r.toInteger=r.toInt,r.toBool=r.toBoolean,r.decodeHTMLEntities=r.decodeHtmlEntities,typeof module!="undefined"&&typeof module.exports!="undefined"?(module.exports=c,module.exports.extendPrototype=s,module.exports.restorePrototype=o,module.exports.VERSION=e):typeof define=="function"&&define.amd?define([],function(){return c}):(window.S=c,window.S.extendPrototype=s,window.S.restorePrototype=o,window.S.VERSION=e);var p={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"},d={};for(var v in p)d[p[v]]=v}).call(this); |
{ | ||
"name": "string", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "string contains methods that aren't included in the vanilla JavaScript string such as escaping HTML, decoding HTML entities, stripping tags, etc.", | ||
@@ -5,0 +5,0 @@ "homepage": [ |
@@ -206,3 +206,3 @@ [string.js](http://stringjs.com) | ||
### - decodeHtmlEntities() ### | ||
### - decodeHTMLEntities() ### | ||
@@ -212,4 +212,4 @@ Decodes HTML entities into their string representation. | ||
```javascript | ||
S('Ken Thompson & Dennis Ritchie').decodeHtmlEntities().s; //'Ken Thompson & Dennis Ritchie' | ||
S('3 < 4').decodeHtmlEntities().s; //'3 < 4' | ||
S('Ken Thompson & Dennis Ritchie').decodeHTMLEntities().s; //'Ken Thompson & Dennis Ritchie' | ||
S('3 < 4').decodeHTMLEntities().s; //'3 < 4' | ||
``` | ||
@@ -216,0 +216,0 @@ |
@@ -88,6 +88,6 @@ | ||
describe('- decodeHtmlEntities()', function() { | ||
describe('- decodeHTMLEntities()', function() { | ||
it('should decode HTML entities into their proper string representation', function() { | ||
T (S('Ken Thompson & Dennis Ritchie').decodeHtmlEntities().s === 'Ken Thompson & Dennis Ritchie'); | ||
T (S('3 < 4').decodeHtmlEntities().s === '3 < 4'); | ||
T (S('Ken Thompson & Dennis Ritchie').decodeHTMLEntities().s === 'Ken Thompson & Dennis Ritchie'); | ||
T (S('3 < 4').decodeHTMLEntities().s === '3 < 4'); | ||
}) | ||
@@ -133,5 +133,7 @@ }) | ||
T (S("FJslfjkasfs").isAlpha()); | ||
T (S("áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ").isAlpha()); | ||
F (S("adflj43faljsdf").isAlpha()); | ||
F (S("33").isAlpha()); | ||
F (S("TT....TTTafafetstYY").isAlpha()); | ||
F (S("-áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ").isAlpha()); | ||
}) | ||
@@ -147,5 +149,7 @@ }) | ||
T (S("Infinity").isAlphaNumeric()); | ||
T (S("áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ1234567890").isAlphaNumeric()); | ||
F (S("-Infinity").isAlphaNumeric()); | ||
F (S("-33").isAlphaNumeric()); | ||
F (S("aaff..").isAlphaNumeric()); | ||
F (S(".áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ1234567890").isAlphaNumeric()); | ||
}) | ||
@@ -171,4 +175,9 @@ }) | ||
T (S('hijp').isLower()); | ||
T (S('áéúóúãõàèìòùâêîôûäëïöüç').isLower()); | ||
T (S('áéúóúãõàèìòùâêîôûäëïöüça').isLower()); | ||
F (S('hi jp').isLower()); | ||
F (S('HelLO').isLower()); | ||
F (S('ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÇ').isLower()); | ||
F (S('áéúóúãõàèìòùâêîôûäëïöüçÁ').isLower()); | ||
F (S('áéúóúãõàèìòùâêîôû äëïöüç').isLower()); | ||
}) | ||
@@ -197,4 +206,8 @@ }) | ||
T (S('HIJP').isUpper()); | ||
T (S('ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÇ').isUpper()); | ||
F (S('HI JP').isUpper()); | ||
F (S('HelLO').isUpper()); | ||
F (S('áéúóúãõàèìòùâêîôûäëïöüç').isUpper()); | ||
F (S('áéúóúãõàèìòùâêîôûäëïöüçÁ').isUpper()); | ||
F (S('ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÇá').isUpper()); | ||
}) | ||
@@ -286,3 +299,4 @@ }) | ||
T (S(' does IT work? ').replaceAll(' ', '_').s === '_does_IT_work?_'); | ||
T (S('Yes it does!').replaceAll(' ', '').s === 'Yesitdoes!'); | ||
T (S('Yes it does!').replaceAll(' ', '').s === 'Yesitdoes!') | ||
T (S('lalala.blabla').replaceAll('.', '_').s === 'lalala_blabla') | ||
@@ -326,2 +340,3 @@ var e = '\\', q = '"'; | ||
T (S('Global Thermonuclear Warfare').slugify().s === 'global-thermonuclear-warfare') | ||
T (S('Fast JSON Parsing').slugify().s === 'fast-json-parsing') | ||
}) | ||
@@ -328,0 +343,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78700
1122