Socket
Socket
Sign inDemoInstall

underscore.string

Package Overview
Dependencies
0
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 2.2.1

2

dist/underscore.string.min.js

@@ -1,1 +0,1 @@

(function(a){"use strict";var b=String.prototype.trim,c=String.prototype.trimRight,d=String.prototype.trimLeft,e=function(a){return a*1||0},f=function(a,b,c){a+="",b=~~b;for(var d=[];b>0;d[--b]=a);return d.join(c==null?"":c)},g=function(a){return Array.prototype.slice.call(a)},h=function(a){return a!=null?"["+j.escapeRegExp(""+a)+"]":"\\s"},i=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}var b=f,c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e=1,f=c.length,g="",h,j=[],k,l,m,n,o,p;for(k=0;k<f;k++){g=a(c[k]);if(g==="string")j.push(c[k]);else if(g==="array"){m=c[k];if(m[2]){h=d[e];for(l=0;l<m[2].length;l++){if(!h.hasOwnProperty(m[2][l]))throw new Error(i('[_.sprintf] property "%s" does not exist',m[2][l]));h=h[m[2][l]]}}else m[1]?h=d[m[1]]:h=d[e++];if(/[^s]/.test(m[8])&&a(h)!="number")throw new Error(i("[_.sprintf] expecting number but found %s",a(h)));switch(m[8]){case"b":h=h.toString(2);break;case"c":h=String.fromCharCode(h);break;case"d":h=parseInt(h,10);break;case"e":h=m[7]?h.toExponential(m[7]):h.toExponential();break;case"f":h=m[7]?parseFloat(h).toFixed(m[7]):parseFloat(h);break;case"o":h=h.toString(8);break;case"s":h=(h=String(h))&&m[7]?h.substring(0,m[7]):h;break;case"u":h=Math.abs(h);break;case"x":h=h.toString(16);break;case"X":h=h.toString(16).toUpperCase()}h=/[def]/.test(m[8])&&m[3]&&h>=0?"+"+h:h,o=m[4]?m[4]=="0"?"0":m[4].charAt(1):" ",p=m[6]-String(h).length,n=m[6]?b(o,p):"",j.push(m[5]?h+n:n+h)}}return j.join("")},c.cache={},c.parse=function(a){var b=a,c=[],d=[],e=0;while(b){if((c=/^[^\x25]+/.exec(b))!==null)d.push(c[0]);else if((c=/^\x25{2}/.exec(b))!==null)d.push("%");else{if((c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b))===null)throw new Error("[_.sprintf] huh?");if(c[2]){e|=1;var f=[],g=c[2],h=[];if((h=/^([a-z_][a-z_\d]*)/i.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1]);while((g=g.substring(h[0].length))!=="")if((h=/^\.([a-z_][a-z_\d]*)/i.exec(g))!==null)f.push(h[1]);else{if((h=/^\[(\d+)\]/.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1])}c[2]=f}else e|=2;if(e===3)throw new Error("[_.sprintf] mixing positional and named placeholders is not (yet) supported");d.push(c)}b=b.substring(c[0].length)}return d},c}(),j={VERSION:"2.1.1",isBlank:function(a){return/^\s*$/.test(a)},stripTags:function(a){return(""+a).replace(/<\/?[^>]+>/ig,"")},capitalize:function(a){return a+="",a.charAt(0).toUpperCase()+a.substring(1).toLowerCase()},chop:function(a,b){a+="",b=~~b||a.length;var c=[];for(var d=0;d<a.length;)c.push(a.slice(d,d+b)),d+=b;return c},clean:function(a){return j.strip((""+a).replace(/\s+/g," "))},count:function(a,b){return a+="",b+="",a.split(b).length-1},chars:function(a){return(""+a).split("")},escapeHTML:function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")},unescapeHTML:function(a){return(""+a).replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&")},escapeRegExp:function(a){return a.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},insert:function(a,b,c){var d=(""+a).split("");return d.splice(~~b,0,""+c),d.join("")},include:function(a,b){return(""+a).indexOf(b)!==-1},join:function(a){var b=g(arguments);return b.join(b.shift())},lines:function(a){return(""+a).split("\n")},reverse:function(a){return Array.prototype.reverse.apply(String(a).split("")).join("")},splice:function(a,b,c,d){var e=(""+a).split("");return e.splice(~~b,~~c,d),e.join("")},startsWith:function(a,b){return a+="",b+="",a.length>=b.length&&a.substring(0,b.length)===b},endsWith:function(a,b){return a+="",b+="",a.length>=b.length&&a.substring(a.length-b.length)===b},succ:function(a){a+="";var b=a.split("");return b.splice(a.length-1,1,String.fromCharCode(a.charCodeAt(a.length-1)+1)),b.join("")},titleize:function(a){return(""+a).replace(/\b./g,function(a){return a.toUpperCase()})},camelize:function(a){return j.trim(a).replace(/(\-|_|\s)+(.)?/g,function(a,b,c){return c?c.toUpperCase():""})},underscored:function(a){return j.trim(a).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()},dasherize:function(a){return j.trim(a).replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase()},classify:function(a){return j.titleize(a.replace(/_/g," ")).replace(/\s/g,"")},humanize:function(a){return j.capitalize(this.underscored(a).replace(/_id$/,"").replace(/_/g," "))},trim:function(a,c){return a+="",!c&&b?b.call(a):(c=h(c),a.replace(new RegExp("^"+c+"+|"+c+"+$","g"),""))},ltrim:function(a,b){return!b&&d?d.call(a):(b=h(b),(""+a).replace(new RegExp("^"+b+"+","g"),""))},rtrim:function(a,b){return!b&&c?c.call(a):(b=h(b),(""+a).replace(new RegExp(b+"+$","g"),""))},truncate:function(a,b,c){return a+="",c=c||"...",b=~~b,a.length>b?a.slice(0,b)+c:a},prune:function(a,b,c){a+="",b=~~b,c=c!=null?""+c:"...";var d,e,f=a.replace(/\W/g,function(a){return a.toUpperCase()!==a.toLowerCase()?"A":" "});return e=f.charAt(b),d=f.slice(0,b),e&&e.match(/\S/)&&(d=d.replace(/\s\S+$/,"")),d=j.rtrim(d),(d+c).length>a.length?a:a.substring(0,d.length)+c},words:function(a,b){return j.trim(a,b).split(b||/\s+/)},pad:function(a,b,c,d){a+="";var e="",g=0;b=~~b,c?c.length>1&&(c=c.charAt(0)):c=" ";switch(d){case"right":g=b-a.length,e=f(c,g),a+=e;break;case"both":g=b-a.length,e={left:f(c,Math.ceil(g/2)),right:f(c,Math.floor(g/2))},a=e.left+a+e.right;break;default:g=b-a.length,e=f(c,g),a=e+a}return a},lpad:function(a,b,c){return j.pad(a,b,c)},rpad:function(a,b,c){return j.pad(a,b,c,"right")},lrpad:function(a,b,c){return j.pad(a,b,c,"both")},sprintf:i,vsprintf:function(a,b){return b.unshift(a),i.apply(null,b)},toNumber:function(a,b){var c=e(e(a).toFixed(~~b));return c===0&&""+a!="0"?Number.NaN:c},strRight:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.indexOf(b):-1;return c!=-1?a.slice(c+b.length,a.length):a},strRightBack:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.lastIndexOf(b):-1;return c!=-1?a.slice(c+b.length,a.length):a},strLeft:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.indexOf(b):-1;return c!=-1?a.slice(0,c):a},strLeftBack:function(a,b){a+="",b=b!=null?""+b:b;var c=a.lastIndexOf(b);return c!=-1?a.slice(0,c):a},toSentence:function(a,b,c){b||(b=", "),c||(c=" and ");var d=a.length,e="";for(var f=0;f<d;f++)e+=a[f],f===d-2?e+=c:f<d-1&&(e+=b);return e},slugify:function(a){var b="ąàáäâãćęèéëêìíïîłńòóöôõùúüûñçżź·/_:;",c="aaaaaaceeeeeiiiilnooooouuuunczz",d=new RegExp(h(b),"g");return a=(""+a).toLowerCase(),a=a.replace(d,function(a){var d=b.indexOf(a);return c.charAt(d)||"-"}),j.trim(a.replace(/[^\w\s-]/g,"").replace(/[-\s]+/g,"-"),"-")},exports:function(){var a={};for(var b in this){if(!this.hasOwnProperty(b)||b=="include"||b=="contains"||b=="reverse")continue;a[b]=this[b]}return a},repeat:f};j.strip=j.trim,j.lstrip=j.ltrim,j.rstrip=j.rtrim,j.center=j.lrpad,j.rjust=j.lpad,j.ljust=j.rpad,j.contains=j.include,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=j),exports._s=j):typeof define=="function"&&define.amd?define("underscore.string",function(){return j}):typeof a._!="undefined"?(a._.string=j,a._.str=a._.string):a._={string:j,str:j}})(this||window);
(function(a){"use strict";var b=String.prototype.trim,c=String.prototype.trimRight,d=String.prototype.trimLeft,e=function(a){return a*1||0},f=function(a,b,c){a+="",b=~~b;for(var d=[];b>0;d[--b]=a);return d.join(c==null?"":c)},g=function(a){return Array.prototype.slice.call(a)},h=function(a){return a!=null?"["+m.escapeRegExp(""+a)+"]":"\\s"},i={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"},j={};for(var k in i)j[i[k]]=k;var l=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}var b=f,c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e=1,f=c.length,g="",h,i=[],j,k,m,n,o,p;for(j=0;j<f;j++){g=a(c[j]);if(g==="string")i.push(c[j]);else if(g==="array"){m=c[j];if(m[2]){h=d[e];for(k=0;k<m[2].length;k++){if(!h.hasOwnProperty(m[2][k]))throw new Error(l('[_.sprintf] property "%s" does not exist',m[2][k]));h=h[m[2][k]]}}else m[1]?h=d[m[1]]:h=d[e++];if(/[^s]/.test(m[8])&&a(h)!="number")throw new Error(l("[_.sprintf] expecting number but found %s",a(h)));switch(m[8]){case"b":h=h.toString(2);break;case"c":h=String.fromCharCode(h);break;case"d":h=parseInt(h,10);break;case"e":h=m[7]?h.toExponential(m[7]):h.toExponential();break;case"f":h=m[7]?parseFloat(h).toFixed(m[7]):parseFloat(h);break;case"o":h=h.toString(8);break;case"s":h=(h=String(h))&&m[7]?h.substring(0,m[7]):h;break;case"u":h=Math.abs(h);break;case"x":h=h.toString(16);break;case"X":h=h.toString(16).toUpperCase()}h=/[def]/.test(m[8])&&m[3]&&h>=0?"+"+h:h,o=m[4]?m[4]=="0"?"0":m[4].charAt(1):" ",p=m[6]-String(h).length,n=m[6]?b(o,p):"",i.push(m[5]?h+n:n+h)}}return i.join("")},c.cache={},c.parse=function(a){var b=a,c=[],d=[],e=0;while(b){if((c=/^[^\x25]+/.exec(b))!==null)d.push(c[0]);else if((c=/^\x25{2}/.exec(b))!==null)d.push("%");else{if((c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b))===null)throw new Error("[_.sprintf] huh?");if(c[2]){e|=1;var f=[],g=c[2],h=[];if((h=/^([a-z_][a-z_\d]*)/i.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1]);while((g=g.substring(h[0].length))!=="")if((h=/^\.([a-z_][a-z_\d]*)/i.exec(g))!==null)f.push(h[1]);else{if((h=/^\[(\d+)\]/.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1])}c[2]=f}else e|=2;if(e===3)throw new Error("[_.sprintf] mixing positional and named placeholders is not (yet) supported");d.push(c)}b=b.substring(c[0].length)}return d},c}(),m={VERSION:"2.1.1",isBlank:function(a){return/^\s*$/.test(a)},stripTags:function(a){return(""+a).replace(/<\/?[^>]+>/g,"")},capitalize:function(a){return a+="",a.charAt(0).toUpperCase()+a.substring(1)},chop:function(a,b){a+="",b=~~b||a.length;var c=[];for(var d=0;d<a.length;d+=b)c.push(a.slice(d,d+b));return c},clean:function(a){return m.strip(a).replace(/\s+/g," ")},count:function(a,b){return a+="",b+="",a.split(b).length-1},chars:function(a){return(""+a).split("")},escapeHTML:function(a){return(""+a).replace(/[&<>"']/g,function(a){return"&"+j[a]+";"})},unescapeHTML:function(a){return(""+a).replace(/\&([^;]+);/g,function(a,b){var c;return b in i?i[b]:(c=b.match(/^#x([\da-fA-F]+)$/))?String.fromCharCode(parseInt(c[1],16)):(c=b.match(/^#(\d+)$/))?String.fromCharCode(~~c[1]):a})},escapeRegExp:function(a){return a.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},insert:function(a,b,c){var d=m.chars(a);return d.splice(~~b,0,""+c),d.join("")},include:function(a,b){return!!~(""+a).indexOf(b)},join:function(){var a=g(arguments);return a.join(a.shift())},lines:function(a){return(""+a).split("\n")},reverse:function(a){return m.chars(a).reverse().join("")},splice:function(a,b,c,d){var e=m.chars(a);return e.splice(~~b,~~c,d),e.join("")},startsWith:function(a,b){return a+="",b+="",a.length>=b.length&&a.substring(0,b.length)===b},endsWith:function(a,b){return a+="",b+="",a.length>=b.length&&a.substring(a.length-b.length)===b},succ:function(a){a+="";var b=m.chars(a);return b.splice(a.length-1,1,String.fromCharCode(a.charCodeAt(a.length-1)+1)),b.join("")},titleize:function(a){return(""+a).replace(/\b./g,function(a){return a.toUpperCase()})},camelize:function(a){return m.trim(a).replace(/[-_\s]+(.)?/g,function(a,b){return b&&b.toUpperCase()})},underscored:function(a){return m.trim(a).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()},dasherize:function(a){return m.trim(a).replace(/[_\s]+/g,"-").replace(/([A-Z])/g,"-$1").replace(/-+/g,"-").toLowerCase()},classify:function(a){return a+="",m.titleize(a.replace(/_/g," ")).replace(/\s/g,"")},humanize:function(a){return m.capitalize(this.underscored(a).replace(/_id$/,"").replace(/_/g," "))},trim:function(a,c){return a+="",!c&&b?b.call(a):(c=h(c),a.replace(new RegExp("^"+c+"+|"+c+"+$","g"),""))},ltrim:function(a,b){return a+="",!b&&d?d.call(a):(b=h(b),a.replace(new RegExp("^"+b+"+"),""))},rtrim:function(a,b){return a+="",!b&&c?c.call(a):(b=h(b),a.replace(new RegExp(b+"+$"),""))},truncate:function(a,b,c){return a+="",c=c||"...",b=~~b,a.length>b?a.slice(0,b)+c:a},prune:function(a,b,c){a+="",b=~~b,c=c!=null?""+c:"...";var d,e,f=a.replace(/\W/g,function(a){return a.toUpperCase()!==a.toLowerCase()?"A":" "});return e=f.charAt(b),d=f.slice(0,b),e&&e.match(/\S/)&&(d=d.replace(/\s\S+$/,"")),d=m.rtrim(d),(d+c).length>a.length?a:a.substring(0,d.length)+c},words:function(a,b){return m.trim(a,b).split(b||/\s+/)},pad:function(a,b,c,d){a+="";var e=0;b=~~b,c?c.length>1&&(c=c.charAt(0)):c=" ";switch(d){case"right":return e=b-a.length,a+f(c,e);case"both":return e=b-a.length,f(c,Math.ceil(e/2))+a+f(c,Math.floor(e/2));default:return e=b-a.length,f(c,e)+a}},lpad:function(a,b,c){return m.pad(a,b,c)},rpad:function(a,b,c){return m.pad(a,b,c,"right")},lrpad:function(a,b,c){return m.pad(a,b,c,"both")},sprintf:l,vsprintf:function(a,b){return b.unshift(a),l.apply(null,b)},toNumber:function(a,b){a+="";var c=e(e(a).toFixed(~~b));return c===0&&!a.match(/^0+$/)?Number.NaN:c},strRight:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.indexOf(b):-1;return~c?a.slice(c+b.length,a.length):a},strRightBack:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.lastIndexOf(b):-1;return~c?a.slice(c+b.length,a.length):a},strLeft:function(a,b){a+="",b=b!=null?""+b:b;var c=b?a.indexOf(b):-1;return~c?a.slice(0,c):a},strLeftBack:function(a,b){a+="",b=b!=null?""+b:b;var c=a.lastIndexOf(b);return~c?a.slice(0,c):a},toSentence:function(a,b,c){b||(b=", "),c||(c=" and ");var d=a.length,e="";for(var f=0;f<d;f++)e+=a[f],f===d-2?e+=c:f<d-1&&(e+=b);return e},slugify:function(a){var b="ąàáäâãćęèéëêìíïîłńòóöôõùúüûñçżź",c="aaaaaaceeeeeiiiilnooooouuuunczz",d=new RegExp(h(b),"g");return a=(""+a).toLowerCase(),a=a.replace(d,function(a){var d=b.indexOf(a);return c.charAt(d)||"-"}),m.trim(a.replace(/[^\w\s-]/g,"").replace(/[-\s]+/g,"-"),"-")},exports:function(){var a={};for(var b in this){if(!this.hasOwnProperty(b)||~m.words("include contains reverse").indexOf(b))continue;a[b]=this[b]}return a},repeat:f};m.strip=m.trim,m.lstrip=m.ltrim,m.rstrip=m.rtrim,m.center=m.lrpad,m.rjust=m.lpad,m.ljust=m.rpad,m.contains=m.include,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=m),exports._s=m):typeof define=="function"&&define.amd?define("underscore.string",function(){return m}):(a._=a._||{},a._.string=a._.str=m)})(this||window);

@@ -7,3 +7,3 @@ // Underscore.string

// Version 2.1.1
// Version 2.2.0rc

@@ -39,2 +39,13 @@ (function(root){

};
var escapeChars = {
lt: '<',
gt: '>',
quot: '"',
apos: "'",
amp: '&'
};
var reversedEscapeChars = {};
for(var key in escapeChars){ reversedEscapeChars[escapeChars[key]] = key; }

@@ -169,3 +180,3 @@ // sprintf() for JavaScript 0.7-beta1

VERSION: '2.1.1',
VERSION: '2.2.0rc',

@@ -177,3 +188,3 @@ isBlank: function(str){

stripTags: function(str){
return (''+str).replace(/<\/?[^>]+>/ig, '');
return (''+str).replace(/<\/?[^>]+>/g, '');
},

@@ -183,3 +194,3 @@

str += '';
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
return str.charAt(0).toUpperCase() + str.substring(1);
},

@@ -191,6 +202,4 @@

var arr = [];
for (var i = 0; i < str.length;) {
for (var i = 0; i < str.length; i += step)
arr.push(str.slice(i,i + step));
i = i + step;
}
return arr;

@@ -200,3 +209,3 @@ },

clean: function(str){
return _s.strip((''+str).replace(/\s+/g, ' '));
return _s.strip(str).replace(/\s+/g, ' ');
},

@@ -214,9 +223,19 @@

escapeHTML: function(str) {
return (''+str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
.replace(/"/g, '&quot;').replace(/'/g, "&apos;");
return (''+str).replace(/[&<>"']/g, function(match){ return '&' + reversedEscapeChars[match] + ';'; });
},
unescapeHTML: function(str) {
return (''+str).replace(/&lt;/g, '<').replace(/&gt;/g, '>')
.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, '&');
return (''+str).replace(/\&([^;]+);/g, function(entity, entityCode){
var match;
if (entityCode in escapeChars) {
return escapeChars[entityCode];
} else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
return String.fromCharCode(parseInt(match[1], 16));
} else if (match = entityCode.match(/^#(\d+)$/)) {
return String.fromCharCode(~~match[1]);
} else {
return entity;
}
});
},

@@ -230,3 +249,3 @@

insert: function(str, i, substr){
var arr = (''+str).split('');
var arr = _s.chars(str);
arr.splice(~~i, 0, ''+substr);

@@ -237,6 +256,6 @@ return arr.join('');

include: function(str, needle){
return (''+str).indexOf(needle) !== -1;
return !!~(''+str).indexOf(needle);
},
join: function(sep) {
join: function() {
var args = slice(arguments);

@@ -251,7 +270,7 @@ return args.join(args.shift());

reverse: function(str){
return Array.prototype.reverse.apply(String(str).split('')).join('');
return _s.chars(str).reverse().join('');
},
splice: function(str, i, howmany, substr){
var arr = (''+str).split('');
var arr = _s.chars(str);
arr.splice(~~i, ~~howmany, substr);

@@ -273,3 +292,3 @@ return arr.join('');

str += '';
var arr = str.split('');
var arr = _s.chars(str);
arr.splice(str.length-1, 1, String.fromCharCode(str.charCodeAt(str.length-1) + 1));

@@ -284,4 +303,4 @@ return arr.join('');

camelize: function(str){
return _s.trim(str).replace(/(\-|_|\s)+(.)?/g, function(match, separator, chr) {
return chr ? chr.toUpperCase() : '';
return _s.trim(str).replace(/[-_\s]+(.)?/g, function(match, chr){
return chr && chr.toUpperCase();
});

@@ -299,2 +318,3 @@ },

classify: function(str){
str += '';
return _s.titleize(str.replace(/_/g, ' ')).replace(/\s/g, '')

@@ -309,5 +329,3 @@ },

str += '';
if (!characters && nativeTrim) {
return nativeTrim.call(str);
}
if (!characters && nativeTrim) { return nativeTrim.call(str); }
characters = defaultToWhiteSpace(characters);

@@ -318,2 +336,3 @@ return str.replace(new RegExp('\^' + characters + '+|' + characters + '+$', 'g'), '');

ltrim: function(str, characters){
str+='';
if (!characters && nativeTrimLeft) {

@@ -323,6 +342,7 @@ return nativeTrimLeft.call(str);

characters = defaultToWhiteSpace(characters);
return (''+str).replace(new RegExp('\^' + characters + '+', 'g'), '');
return str.replace(new RegExp('^' + characters + '+'), '');
},
rtrim: function(str, characters){
str+='';
if (!characters && nativeTrimRight) {

@@ -332,3 +352,3 @@ return nativeTrimRight.call(str);

characters = defaultToWhiteSpace(characters);
return (''+str).replace(new RegExp(characters + '+$', 'g'), '');
return str.replace(new RegExp(characters + '+$'), '');
},

@@ -375,3 +395,3 @@

var padding = '', padlen = 0;
var padlen = 0;

@@ -389,19 +409,12 @@ length = ~~length;

padlen = (length - str.length);
padding = strRepeat(padStr, padlen);
str = str+padding;
break;
return str + strRepeat(padStr, padlen);
case 'both':
padlen = (length - str.length);
padding = {
'left' : strRepeat(padStr, Math.ceil(padlen/2)),
'right': strRepeat(padStr, Math.floor(padlen/2))
};
str = padding.left+str+padding.right;
break;
return strRepeat(padStr, Math.ceil(padlen/2)) +
str +
strRepeat(padStr, Math.floor(padlen/2));
default: // 'left'
padlen = (length - str.length);
padding = strRepeat(padStr, padlen);;
str = padding+str;
return strRepeat(padStr, padlen) + str;
}
return str;
},

@@ -429,4 +442,5 @@

toNumber: function(str, decimals) {
str += '';
var num = parseNumber(parseNumber(str).toFixed(~~decimals));
return num === 0 && ''+str !== '0' ? Number.NaN : num;
return num === 0 && !str.match(/^0+$/) ? Number.NaN : num;
},

@@ -436,4 +450,4 @@

str += ''; sep = sep != null ? ''+sep : sep;
var pos = (!sep) ? -1 : str.indexOf(sep);
return (pos != -1) ? str.slice(pos+sep.length, str.length) : str;
var pos = !sep ? -1 : str.indexOf(sep);
return ~pos ? str.slice(pos+sep.length, str.length) : str;
},

@@ -443,4 +457,4 @@

str += ''; sep = sep != null ? ''+sep : sep;
var pos = (!sep) ? -1 : str.lastIndexOf(sep);
return (pos != -1) ? str.slice(pos+sep.length, str.length) : str;
var pos = !sep ? -1 : str.lastIndexOf(sep);
return ~pos ? str.slice(pos+sep.length, str.length) : str;
},

@@ -450,4 +464,4 @@

str += ''; sep = sep != null ? ''+sep : sep;
var pos = (!sep) ? -1 : str.indexOf(sep);
return (pos != -1) ? str.slice(0, pos) : str;
var pos = !sep ? -1 : str.indexOf(sep);
return ~pos ? str.slice(0, pos) : str;
},

@@ -458,3 +472,3 @@

var pos = str.lastIndexOf(sep);
return (pos != -1) ? str.slice(0, pos) : str;
return ~pos ? str.slice(0, pos) : str;
},

@@ -477,3 +491,3 @@

slugify: function(str) {
var from = "ąàáäâãćęèéëêìíïîłńòóöôõùúüûñçżź·/_:;",
var from = "ąàáäâãćęèéëêìíïîłńòóöôõùúüûñçżź",
to = "aaaaaaceeeeeiiiilnooooouuuunczz",

@@ -496,3 +510,3 @@ regex = new RegExp(defaultToWhiteSpace(from), 'g');

for (var prop in this) {
if (!this.hasOwnProperty(prop) || prop == 'include' || prop == 'contains' || prop == 'reverse') continue;
if (!this.hasOwnProperty(prop) || ~_s.words('include contains reverse').indexOf(prop)) continue;
result[prop] = this[prop];

@@ -505,3 +519,2 @@ }

repeat: strRepeat
};

@@ -532,17 +545,10 @@

});
// Integrate with Underscore.js
} else if (typeof root._ !== 'undefined') {
// root._.mixin(_s);
root._.string = _s;
root._.str = root._.string;
// Or define it
} else {
root._ = {
string: _s,
str: _s
};
// Integrate with Underscore.js if defined
// or create our own underscore object.
root._ = root._ || {};
root._.string = root._.str = _s;
}
}(this || window));
{
"name": "underscore.string",
"version": "2.1.1",
"version": "2.2.1",
"description": "String manipulation extensions for Underscore.js javascript library.",

@@ -5,0 +5,0 @@ "homepage": "http://epeli.github.com/underscore.string/",

@@ -66,2 +66,3 @@ $(document).ready(function() {

equals(_.capitalize("fabio"), "Fabio", 'First letter is upper case');
equals(_.capitalize('FOO'), 'FOO', 'Other letters unchanged');
equals(_(123).capitalize(), "123", "Non string");

@@ -145,2 +146,7 @@ });

});
test('String: clean', function(){
equals(_.clean(' foo bar '), 'foo bar');
equals(_.clean(1), '1');
});

@@ -211,4 +217,17 @@ test('String: count', function(){

});
test('String: camelize', function(){
equals(_.camelize('-moz-transform'), 'MozTransform');
equals(_.camelize('webkit-transform'), 'webkitTransform');
equals(_.camelize('under_scored'), 'underScored');
equals(_.camelize(' with spaces'), 'withSpaces');
});
test('String: join', function(){
equals(_.join(1, 2, 3, 4), '21314');
equals(_.join('|', 'foo', 'bar', 'baz'), 'foo|bar|baz');
});
test('String: classify', function(){
equals(_.classify(1), '1');
equals(_('some_class_name').classify(), 'SomeClassName');

@@ -272,2 +291,11 @@ });

equals(_('&amp;lt;').unescapeHTML(), '&lt;');
equals(_('&#39;').unescapeHTML(), "'");
equals(_('&#0039;').unescapeHTML(), "'");
equals(_('&#x4a;').unescapeHTML(), "J");
equals(_('&#x04A;').unescapeHTML(), "J");
equals(_('&#X4A;').unescapeHTML(), "&#X4A;");
equals(_('&_#39;').unescapeHTML(), "&_#39;");
equals(_('&#39_;').unescapeHTML(), "&#39_;");
equals(_('&amp;#38;').unescapeHTML(), "&#38;");
equals(_('&#38;amp;').unescapeHTML(), "&amp;");
equals(_(5).unescapeHTML(), '5');

@@ -334,4 +362,5 @@ // equals(_(undefined).unescapeHTML(), '');

deepEqual(_("not a number").toNumber(), Number.NaN);
equals(_(0).toNumber(), 0);
equals(_("0").toNumber(), 0);
equals(_(0).toNumber(), 0);
equals(_("0").toNumber(), 0);
equals(_("0000").toNumber(), 0);
equals(_("2.345").toNumber(), 2);

@@ -338,0 +367,0 @@ equals(_("2.345").toNumber(NaN), 2);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc