Socket
Socket
Sign inDemoInstall

underscore.string

Package Overview
Dependencies
1
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.3 to 1.1.4

17

dist/underscore.string.min.js

@@ -1,8 +0,9 @@

(function(){function g(b){if(b)return e.escapeRegExp(b);return"\\s"}var h=String.prototype.trim,e={isBlank:function(b){return!!b.match(/^\s*$/)},capitalize:function(b){return b.charAt(0).toUpperCase()+b.substring(1).toLowerCase()},chop:function(b,a){a=a||b.length;for(var c=[],f=0;f<b.length;)c.push(b.slice(f,f+a)),f+=a;return c},clean:function(b){return e.strip(b.replace(/\s+/g," "))},count:function(b,a){for(var c=0,f,d=0;d<b.length;)f=b.indexOf(a,d),f>=0&&c++,d=d+(f>=0?f:0)+a.length;return c},chars:function(b){return b.split("")},
escapeHTML:function(b){return String(b||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},unescapeHTML:function(b){return String(b||"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")},escapeRegExp:function(b){return String(b||"").replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},insert:function(b,a,c){b=b.split("");b.splice(a,0,c);return b.join("")},includes:function(b,a){return b.indexOf(a)!==-1},join:function(b){b=String(b);for(var a="",c=1;c<arguments.length;c+=1)a+=
String(arguments[c]),c!==arguments.length-1&&(a+=b);return a},lines:function(b){return b.split("\n")},splice:function(b,a,c,f){b=b.split("");b.splice(a,c,f);return b.join("")},startsWith:function(b,a){return b.length>=a.length&&b.substring(0,a.length)===a},endsWith:function(b,a){return b.length>=a.length&&b.substring(b.length-a.length)===a},succ:function(b){var a=b.split("");a.splice(b.length-1,1,String.fromCharCode(b.charCodeAt(b.length-1)+1));return a.join("")},titleize:function(b){b=b.split(" ");
for(var a,c=0;c<b.length;c++)a=b[c].split(""),typeof a[0]!=="undefined"&&(a[0]=a[0].toUpperCase()),c+1===b.length?b[c]=a.join(""):b[c]=a.join("")+" ";return b.join("")},camelize:function(b){return e.trim(b).replace(/(\-|_|\s)+(.)?/g,function(a,b,f){return f?f.toUpperCase():""})},underscored:function(b){return e.trim(b).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/\-|\s+/g,"_").toLowerCase()},dasherize:function(b){return e.trim(b).replace(/([a-z\d])([A-Z]+)/g,"$1-$2").replace(/^([A-Z]+)/,"-$1").replace(/\_|\s+/g,
"-").toLowerCase()},trim:function(b,a){if(!a&&h)return h.call(b);a=g(a);return b.replace(RegExp("^["+a+"]+|["+a+"]+$","g"),"")},ltrim:function(b,a){a=g(a);return b.replace(RegExp("^["+a+"]+","g"),"")},rtrim:function(b,a){a=g(a);return b.replace(RegExp("["+a+"]+$","g"),"")},truncate:function(b,a,c){return b.slice(0,a)+(c||"...")},words:function(b,a){return b.split(a||" ")},sprintf:function(){for(var b=0,a,c=arguments[b++],f=[],d,e,g;c;){if(d=/^[^\x25]+/.exec(c))f.push(d[0]);else if(d=/^\x25{2}/.exec(c))f.push("%");
else if(d=/^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(c)){if((a=arguments[d[1]||b++])==null||a==void 0)throw"Too few arguments.";if(/[^s]/.test(d[7])&&typeof a!="number")throw"Expecting number but found "+typeof a;switch(d[7]){case "b":a=a.toString(2);break;case "c":a=String.fromCharCode(a);break;case "d":a=parseInt(a);break;case "e":a=d[6]?a.toExponential(d[6]):a.toExponential();break;case "f":a=d[6]?parseFloat(a).toFixed(d[6]):parseFloat(a);break;case "o":a=a.toString(8);
break;case "s":a=(a=String(a))&&d[6]?a.substring(0,d[6]):a;break;case "u":a=Math.abs(a);break;case "x":a=a.toString(16);break;case "X":a=a.toString(16).toUpperCase()}a=/[def]/.test(d[7])&&d[2]&&a>=0?"+"+a:a;e=d[3]?d[3]=="0"?"0":d[3].charAt(1):" ";g=d[5]-String(a).length-0;if(d[5]){for(var h=[];g>0;h[--g]=e);e=h.join("")}else e="";f.push(""+(d[4]?a+e:e+a))}else throw"Huh ?!";c=c.substring(d[0].length)}return f.join("")}};e.strip=e.trim;e.lstrip=e.ltrim;e.rstrip=e.rtrim;typeof window==="undefined"&&
typeof module!=="undefined"?module.exports=e:typeof this._!=="undefined"?this._.mixin(e):this._=e})();
(function(){function g(b,a){for(var c=[];a>0;c[--a]=b);return c.join("")}function f(b){if(b)return d.escapeRegExp(b);return"\\s"}var i=String.prototype.trim,d={isBlank:function(b){return!!b.match(/^\s*$/)},capitalize:function(b){return b.charAt(0).toUpperCase()+b.substring(1).toLowerCase()},chop:function(b,a){a=a||b.length;for(var c=[],d=0;d<b.length;)c.push(b.slice(d,d+a)),d+=a;return c},clean:function(b){return d.strip(b.replace(/\s+/g," "))},count:function(b,a){for(var c=0,d,e=0;e<b.length;)d=
b.indexOf(a,e),d>=0&&c++,e=e+(d>=0?d:0)+a.length;return c},chars:function(b){return b.split("")},escapeHTML:function(b){return String(b||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},unescapeHTML:function(b){return String(b||"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")},escapeRegExp:function(b){return String(b||"").replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},insert:function(b,a,c){b=b.split("");b.splice(a,0,c);return b.join("")},includes:function(b,a){return b.indexOf(a)!==
-1},join:function(b){b=String(b);for(var a="",c=1;c<arguments.length;c+=1)a+=String(arguments[c]),c!==arguments.length-1&&(a+=b);return a},lines:function(b){return b.split("\n")},splice:function(b,a,c,d){b=b.split("");b.splice(a,c,d);return b.join("")},startsWith:function(b,a){return b.length>=a.length&&b.substring(0,a.length)===a},endsWith:function(b,a){return b.length>=a.length&&b.substring(b.length-a.length)===a},succ:function(b){var a=b.split("");a.splice(b.length-1,1,String.fromCharCode(b.charCodeAt(b.length-
1)+1));return a.join("")},titleize:function(b){b=b.split(" ");for(var a,c=0;c<b.length;c++)a=b[c].split(""),typeof a[0]!=="undefined"&&(a[0]=a[0].toUpperCase()),c+1===b.length?b[c]=a.join(""):b[c]=a.join("")+" ";return b.join("")},camelize:function(b){return d.trim(b).replace(/(\-|_|\s)+(.)?/g,function(a,b,d){return d?d.toUpperCase():""})},underscored:function(b){return d.trim(b).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/\-|\s+/g,"_").toLowerCase()},dasherize:function(b){return d.trim(b).replace(/([a-z\d])([A-Z]+)/g,
"$1-$2").replace(/^([A-Z]+)/,"-$1").replace(/\_|\s+/g,"-").toLowerCase()},trim:function(b,a){if(!a&&i)return i.call(b);a=f(a);return b.replace(RegExp("^["+a+"]+|["+a+"]+$","g"),"")},ltrim:function(b,a){a=f(a);return b.replace(RegExp("^["+a+"]+","g"),"")},rtrim:function(b,a){a=f(a);return b.replace(RegExp("["+a+"]+$","g"),"")},truncate:function(b,a,c){return b.slice(0,a)+(c||"...")},words:function(b,a){return b.split(a||" ")},pad:function(b,a,c,d){var e="";e=0;c?c.length>1&&(c=c[0]):c=" ";switch(d){case "right":e=
a-b.length;e=g(c,e);b+=e;break;case "both":e=a-b.length;e={left:g(c,Math.ceil(e/2)),right:g(c,Math.floor(e/2))};b=e.left+b+e.right;break;default:e=a-b.length,e=g(c,e),b=e+b}return b},lpad:function(b,a,c){return d.pad(b,a,c)},rpad:function(b,a,c){return d.pad(b,a,c,"right")},lrpad:function(b,a,c){return d.pad(b,a,c,"both")},sprintf:function(){for(var b=0,a,c=arguments[b++],d=[],e,h,f;c;){if(e=/^[^\x25]+/.exec(c))d.push(e[0]);else if(e=/^\x25{2}/.exec(c))d.push("%");else if(e=/^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(c)){if((a=
arguments[e[1]||b++])==null||a==void 0)throw"Too few arguments.";if(/[^s]/.test(e[7])&&typeof a!="number")throw"Expecting number but found "+typeof a;switch(e[7]){case "b":a=a.toString(2);break;case "c":a=String.fromCharCode(a);break;case "d":a=parseInt(a);break;case "e":a=e[6]?a.toExponential(e[6]):a.toExponential();break;case "f":a=e[6]?parseFloat(a).toFixed(e[6]):parseFloat(a);break;case "o":a=a.toString(8);break;case "s":a=(a=String(a))&&e[6]?a.substring(0,e[6]):a;break;case "u":a=Math.abs(a);
break;case "x":a=a.toString(16);break;case "X":a=a.toString(16).toUpperCase()}a=/[def]/.test(e[7])&&e[2]&&a>=0?"+"+a:a;h=e[3]?e[3]=="0"?"0":e[3].charAt(1):" ";f=e[5]-String(a).length-0;h=e[5]?g(h,f):"";d.push(""+(e[4]?a+h:h+a))}else throw"Huh ?!";c=c.substring(e[0].length)}return d.join("")}};d.strip=d.trim;d.lstrip=d.ltrim;d.rstrip=d.rtrim;d.center=d.lrpad;d.ljust=d.lpad;d.rjust=d.rpad;typeof window==="undefined"&&typeof module!=="undefined"?module.exports=d:typeof this._!=="undefined"?this._.mixin(d):
this._=d})();

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

// Version 1.1.3
// Version 1.1.4

@@ -186,2 +186,45 @@ (function(){

pad: function(str, length, padStr, type) {
var padding = '';
var padlen = 0;
if (!padStr) { padStr = ' '; }
else if (padStr.length > 1) { padStr = padStr[0]; }
switch(type) {
case "right":
padlen = (length - str.length);
padding = str_repeat(padStr, padlen);
str = str+padding;
break;
case "both":
padlen = (length - str.length);
padding = {
'left' : str_repeat(padStr, Math.ceil(padlen/2)),
'right': str_repeat(padStr, Math.floor(padlen/2))
};
str = padding.left+str+padding.right;
break;
default: // "left"
padlen = (length - str.length);
padding = str_repeat(padStr, padlen);;
str = padding+str;
}
return str;
},
lpad: function(str, length, padStr) {
return _s.pad(str, length, padStr);
},
rpad: function(str, length, padStr) {
return _s.pad(str, length, padStr, 'right');
},
lrpad: function(str, length, padStr) {
return _s.pad(str, length, padStr, 'both');
},
/**

@@ -240,5 +283,8 @@ * Credits for this function goes to

_s.strip = _s.trim;
_s.lstrip = _s.ltrim;
_s.rstrip = _s.rtrim;
_s.strip = _s.trim;
_s.lstrip = _s.ltrim;
_s.rstrip = _s.rtrim;
_s.center = _s.lrpad
_s.ljust = _s.lpad
_s.rjust = _s.rpad

@@ -245,0 +291,0 @@ // CommonJS module is defined

{
"name": "underscore.string",
"version": "1.1.3",
"version": "1.1.4",
"description": "String manipulation extensions for Underscore.js javascript library.",

@@ -10,3 +10,6 @@ "homepage": "https://github.com/edtsech/underscore.string",

"Sasha Koss <kossnocorp@gmail.com> (http://koss.nocorp.me/)",
"Vladimir Dronnikov <dronnikov@gmail.com>"
"Vladimir Dronnikov <dronnikov@gmail.com>",
"Pete Kruckenberg (<https://github.com/kruckenb>)",
"Paul Chavard <paul@chavard.net> (<http://tchak.net>)",
"Ed Finkler <coj@funkatron.com> (<http://funkatron.com>)"
],

@@ -25,3 +28,3 @@ "keywords": [

"dependencies": {
"underscore": "1.1.4"
"underscore": "1.1.6"
},

@@ -28,0 +31,0 @@ "repository": {

@@ -85,2 +85,23 @@ (function() {

});
JSLitmus.test('pad default', function(){
_('foo').pad(12);
});
JSLitmus.test('pad hash left', function(){
_('foo').pad(12, '#');
});
JSLitmus.test('pad hash right', function(){
_('foo').pad(12, '#', 'right');
});
JSLitmus.test('pad hash both', function(){
_('foo').pad(12, '#', 'both');
});
JSLitmus.test('pad hash both longPad', function(){
_('foo').pad(12, 'f00f00f00', 'both');
});
})();

@@ -203,2 +203,35 @@ $(document).ready(function() {

});
test('String: pad', function() {
equals(_("1").pad(8), ' 1');
equals(_("1").pad(8, '0'), '00000001');
equals(_("1").pad(8, '0', 'left'), '00000001');
equals(_("1").pad(8, '0', 'right'), '10000000');
equals(_("1").pad(8, '0', 'both'), '00001000');
equals(_("foo").pad(8, '0', 'both'), '000foo00');
equals(_("foo").pad(7, '0', 'both'), '00foo00');
equals(_("foo").pad(7, '!@$%dofjrofj', 'both'), '!!foo!!');
});
test('String: lpad', function() {
equals(_("1").lpad(8), ' 1');
equals(_("1").lpad(8, '0'), '00000001');
equals(_("1").lpad(8, '0', 'left'), '00000001');
});
test('String: rpad', function() {
equals(_("1").rpad(8), '1 ');
equals(_("1").rpad(8, '0'), '10000000');
equals(_("foo").rpad(8, '0'), 'foo00000');
equals(_("foo").rpad(7, '0'), 'foo0000');
});
test('String: lrpad', function() {
equals(_("1").lrpad(8), ' 1 ');
equals(_("1").lrpad(8, '0'), '00001000');
equals(_("foo").lrpad(8, '0'), '000foo00');
equals(_("foo").lrpad(7, '0'), '00foo00');
equals(_("foo").lrpad(7, '!@$%dofjrofj'), '!!foo!!');
});
});

@@ -126,8 +126,8 @@ $(document).ready(function() {

test('collections: all', function() {
ok(_.all([]), 'the empty set');
ok(_.all([true, true, true]), 'all true values');
ok(!_.all([true, false, true]), 'one false value');
ok(_.all([], _.identity), 'the empty set');
ok(_.all([true, true, true], _.identity), 'all true values');
ok(!_.all([true, false, true], _.identity), 'one false value');
ok(_.all([0, 10, 28], function(num){ return num % 2 == 0; }), 'even numbers');
ok(!_.all([0, 11, 28], function(num){ return num % 2 == 0; }), 'an odd number');
ok(_.every([true, true, true]), 'aliased as "every"');
ok(_.every([true, true, true], _.identity), 'aliased as "every"');
});

@@ -158,2 +158,9 @@

test('collections: invoke w/ function reference', function() {
var list = [[5, 1, 7], [3, 2, 1]];
var result = _.invoke(list, Array.prototype.sort);
equals(result[0].join(', '), '1, 5, 7', 'first array sorted');
equals(result[1].join(', '), '1, 2, 3', 'second array sorted');
});
test('collections: pluck', function() {

@@ -160,0 +167,0 @@ var people = [{name : 'moe', age : 30}, {name : 'curly', age : 50}];

@@ -23,2 +23,11 @@ $(document).ready(function() {

equals(func(), 'hello: curly', 'the function was completely applied in advance');
var func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname; };
func = _.bind(func, this, 'hello', 'moe', 'curly');
equals(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments');
func = function(context, message) { equals(this, context, message); };
_.bind(func, 0, 0, 'can bind a function to `0`')();
_.bind(func, '', '', 'can bind a function to an empty string')();
_.bind(func, false, false, 'can bind a function to `false`')();
});

@@ -103,2 +112,10 @@

test("functions: once", function() {
var num = 0;
var increment = _.once(function(){ num++; });
increment();
increment();
equals(num, 1);
});
test("functions: wrap", function() {

@@ -125,2 +142,16 @@ var greet = function(name){ return "hi: " + name; };

test("functions: after", function() {
var testAfter = function(afterAmount, timesCalled) {
var afterCalled = 0;
var after = _.after(afterAmount, function() {
afterCalled++;
});
while (timesCalled--) after();
return afterCalled;
};
equals(testAfter(5, 5), 1, "after(N) should fire after being called N times");
equals(testAfter(5, 4), 0, "after(N) should not fire unless called N times");
});
});

@@ -6,3 +6,12 @@ $(document).ready(function() {

test("objects: keys", function() {
var exception = /object/;
equals(_.keys({one : 1, two : 2}).join(', '), 'one, two', 'can extract the keys from an object');
// the test above is not safe because it relies on for-in enumeration order
var a = []; a[1] = 0;
equals(_.keys(a).join(', '), '1', 'is not fooled by sparse arrays; see issue #95');
raises(function() { _.keys(null); }, exception, 'throws an error for `null` values');
raises(function() { _.keys(void 0); }, exception, 'throws an error for `undefined` values');
raises(function() { _.keys(1); }, exception, 'throws an error for number primitives');
raises(function() { _.keys('a'); }, exception, 'throws an error for string primitives');
raises(function() { _.keys(true); }, exception, 'throws an error for boolean primitives');
});

@@ -28,2 +37,4 @@

ok(_.isEqual(result, {x:2, a:'b'}), 'extending from multiple source objects last property trumps');
result = _.extend({}, {a: void 0, b: null});
equals(_.keys(result).join(''), 'b', 'extend does not copy undefined values');
});

@@ -30,0 +41,0 @@

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

// Underscore.js 1.1.4
// Underscore.js 1.1.6
// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.

@@ -24,3 +24,3 @@ // Underscore is freely distributable under the MIT license.

// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;

@@ -46,3 +46,4 @@ // Create quick reference variables for speed access to core prototypes.

nativeIsArray = Array.isArray,
nativeKeys = Object.keys;
nativeKeys = Object.keys,
nativeBind = FuncProto.bind;

@@ -63,3 +64,3 @@ // Create a safe reference to the Underscore object for use below.

// Current version.
_.VERSION = '1.1.4';
_.VERSION = '1.1.6';

@@ -173,3 +174,2 @@ // Collection Functions

_.every = _.all = function(obj, iterator, context) {
iterator = iterator || _.identity;
var result = true;

@@ -188,3 +188,3 @@ if (obj == null) return result;

var any = _.some = _.any = function(obj, iterator, context) {
iterator = iterator || _.identity;
iterator || (iterator = _.identity);
var result = false;

@@ -215,3 +215,3 @@ if (obj == null) return result;

return _.map(obj, function(value) {
return (method ? value[method] : value).apply(value, args);
return (method.call ? method || value : value[method]).apply(value, args);
});

@@ -263,3 +263,3 @@ };

_.sortedIndex = function(array, obj, iterator) {
iterator = iterator || _.identity;
iterator || (iterator = _.identity);
var low = 0, high = array.length;

@@ -416,6 +416,9 @@ while (low < high) {

// optionally). Binding with arguments is also known as `curry`.
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
// We check for `func.bind` first, to fail fast when `func` is undefined.
_.bind = function(func, obj) {
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
var args = slice.call(arguments, 2);
return function() {
return func.apply(obj || {}, args.concat(slice.call(arguments)));
return func.apply(obj, args.concat(slice.call(arguments)));
};

@@ -436,3 +439,3 @@ };

var memo = {};
hasher = hasher || _.identity;
hasher || (hasher = _.identity);
return function() {

@@ -484,2 +487,13 @@ var key = hasher.apply(this, arguments);

// Returns a function that will be executed at most one time, no matter how
// often you call it. Useful for lazy initialization.
_.once = function(func) {
var ran = false, memo;
return function() {
if (ran) return memo;
ran = true;
return memo = func.apply(this, arguments);
};
};
// Returns the first function passed as an argument to the second,

@@ -508,2 +522,10 @@ // allowing you to adjust arguments, run code before and after, and

// Returns a function that will only be executed after being called N times.
_.after = function(times, func) {
return function() {
if (--times < 1) { return func.apply(this, arguments); }
};
};
// Object Functions

@@ -515,2 +537,3 @@ // ----------------

_.keys = nativeKeys || function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];

@@ -535,3 +558,5 @@ for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;

each(slice.call(arguments, 1), function(source) {
for (var prop in source) obj[prop] = source[prop];
for (var prop in source) {
if (source[prop] !== void 0) obj[prop] = source[prop];
}
});

@@ -544,3 +569,5 @@ return obj;

each(slice.call(arguments, 1), function(source) {
for (var prop in source) if (obj[prop] == null) obj[prop] = source[prop];
for (var prop in source) {
if (obj[prop] == null) obj[prop] = source[prop];
}
});

@@ -547,0 +574,0 @@ return obj;

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