Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

8

CHANGELOG.md

@@ -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 @@ ------------------

2

component.json

@@ -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]="&amp;",u==="HTML_ENTITIES"&&(n[160]="&nbsp;",n[161]="&iexcl;",n[162]="&cent;",n[163]="&pound;",n[164]="&curren;",n[165]="&yen;",n[166]="&brvbar;",n[167]="&sect;",n[168]="&uml;",n[169]="&copy;",n[170]="&ordf;",n[171]="&laquo;",n[172]="&not;",n[173]="&shy;",n[174]="&reg;",n[175]="&macr;",n[176]="&deg;",n[177]="&plusmn;",n[178]="&sup2;",n[179]="&sup3;",n[180]="&acute;",n[181]="&micro;",n[182]="&para;",n[183]="&middot;",n[184]="&cedil;",n[185]="&sup1;",n[186]="&ordm;",n[187]="&raquo;",n[188]="&frac14;",n[189]="&frac12;",n[190]="&frac34;",n[191]="&iquest;",n[192]="&Agrave;",n[193]="&Aacute;",n[194]="&Acirc;",n[195]="&Atilde;",n[196]="&Auml;",n[197]="&Aring;",n[198]="&AElig;",n[199]="&Ccedil;",n[200]="&Egrave;",n[201]="&Eacute;",n[202]="&Ecirc;",n[203]="&Euml;",n[204]="&Igrave;",n[205]="&Iacute;",n[206]="&Icirc;",n[207]="&Iuml;",n[208]="&ETH;",n[209]="&Ntilde;",n[210]="&Ograve;",n[211]="&Oacute;",n[212]="&Ocirc;",n[213]="&Otilde;",n[214]="&Ouml;",n[215]="&times;",n[216]="&Oslash;",n[217]="&Ugrave;",n[218]="&Uacute;",n[219]="&Ucirc;",n[220]="&Uuml;",n[221]="&Yacute;",n[222]="&THORN;",n[223]="&szlig;",n[224]="&agrave;",n[225]="&aacute;",n[226]="&acirc;",n[227]="&atilde;",n[228]="&auml;",n[229]="&aring;",n[230]="&aelig;",n[231]="&ccedil;",n[232]="&egrave;",n[233]="&eacute;",n[234]="&ecirc;",n[235]="&euml;",n[236]="&igrave;",n[237]="&iacute;",n[238]="&icirc;",n[239]="&iuml;",n[240]="&eth;",n[241]="&ntilde;",n[242]="&ograve;",n[243]="&oacute;",n[244]="&ocirc;",n[245]="&otilde;",n[246]="&ouml;",n[247]="&divide;",n[248]="&oslash;",n[249]="&ugrave;",n[250]="&uacute;",n[251]="&ucirc;",n[252]="&uuml;",n[253]="&yacute;",n[254]="&thorn;",n[255]="&yuml;"),a!=="ENT_NOQUOTES"&&(n[34]="&quot;"),a==="ENT_QUOTES"&&(n[39]="&#39;"),n[60]="&lt;",n[62]="&gt;";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["&"]="&amp;";for(n in i)r=i[n],s=s.split(r).join(n);return s=s.split("&#039;").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]="&amp;",u==="HTML_ENTITIES"&&(n[160]="&nbsp;",n[161]="&iexcl;",n[162]="&cent;",n[163]="&pound;",n[164]="&curren;",n[165]="&yen;",n[166]="&brvbar;",n[167]="&sect;",n[168]="&uml;",n[169]="&copy;",n[170]="&ordf;",n[171]="&laquo;",n[172]="&not;",n[173]="&shy;",n[174]="&reg;",n[175]="&macr;",n[176]="&deg;",n[177]="&plusmn;",n[178]="&sup2;",n[179]="&sup3;",n[180]="&acute;",n[181]="&micro;",n[182]="&para;",n[183]="&middot;",n[184]="&cedil;",n[185]="&sup1;",n[186]="&ordm;",n[187]="&raquo;",n[188]="&frac14;",n[189]="&frac12;",n[190]="&frac34;",n[191]="&iquest;",n[192]="&Agrave;",n[193]="&Aacute;",n[194]="&Acirc;",n[195]="&Atilde;",n[196]="&Auml;",n[197]="&Aring;",n[198]="&AElig;",n[199]="&Ccedil;",n[200]="&Egrave;",n[201]="&Eacute;",n[202]="&Ecirc;",n[203]="&Euml;",n[204]="&Igrave;",n[205]="&Iacute;",n[206]="&Icirc;",n[207]="&Iuml;",n[208]="&ETH;",n[209]="&Ntilde;",n[210]="&Ograve;",n[211]="&Oacute;",n[212]="&Ocirc;",n[213]="&Otilde;",n[214]="&Ouml;",n[215]="&times;",n[216]="&Oslash;",n[217]="&Ugrave;",n[218]="&Uacute;",n[219]="&Ucirc;",n[220]="&Uuml;",n[221]="&Yacute;",n[222]="&THORN;",n[223]="&szlig;",n[224]="&agrave;",n[225]="&aacute;",n[226]="&acirc;",n[227]="&atilde;",n[228]="&auml;",n[229]="&aring;",n[230]="&aelig;",n[231]="&ccedil;",n[232]="&egrave;",n[233]="&eacute;",n[234]="&ecirc;",n[235]="&euml;",n[236]="&igrave;",n[237]="&iacute;",n[238]="&icirc;",n[239]="&iuml;",n[240]="&eth;",n[241]="&ntilde;",n[242]="&ograve;",n[243]="&oacute;",n[244]="&ocirc;",n[245]="&otilde;",n[246]="&ouml;",n[247]="&divide;",n[248]="&oslash;",n[249]="&ugrave;",n[250]="&uacute;",n[251]="&ucirc;",n[252]="&uuml;",n[253]="&yacute;",n[254]="&thorn;",n[255]="&yuml;"),a!=="ENT_NOQUOTES"&&(n[34]="&quot;"),a==="ENT_QUOTES"&&(n[39]="&#39;"),n[60]="&lt;",n[62]="&gt;";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["&"]="&amp;";for(n in i)r=i[n],s=s.split(r).join(n);return s=s.split("&#039;").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 &amp; Dennis Ritchie').decodeHtmlEntities().s; //'Ken Thompson & Dennis Ritchie'
S('3 &lt; 4').decodeHtmlEntities().s; //'3 < 4'
S('Ken Thompson &amp; Dennis Ritchie').decodeHTMLEntities().s; //'Ken Thompson & Dennis Ritchie'
S('3 &lt; 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 &amp; Dennis Ritchie').decodeHtmlEntities().s === 'Ken Thompson & Dennis Ritchie');
T (S('3 &lt; 4').decodeHtmlEntities().s === '3 < 4');
T (S('Ken Thompson &amp; Dennis Ritchie').decodeHTMLEntities().s === 'Ken Thompson & Dennis Ritchie');
T (S('3 &lt; 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 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc