Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up code and added a few optimizations.

  • Loading branch information...
commit cdaae5a5990b6ab495bbed35679919e3ae6c8223 1 parent 9097f56
Oliver Morgan authored
View
2  Rakefile
@@ -4,7 +4,7 @@ require 'yui/compressor'
desc "Build JSToolkit source into a minified browser version."
task :build do
- source = '(function() {' << File.read('./index.js')
+ source = '(function () {' << File.read('./index.js')
Dir.glob("./lib/*.js") do |file|
source << File.read(file);
end
View
168 dist/jst.js
@@ -1,4 +1,4 @@
-(function() {var domDefineProperty = false, objectIdStore = [], objectDescriptorStore = [];
+(function () {var domDefineProperty = false, objectIdStore = [], objectDescriptorStore = [];
// Whether we have a working version of Object.defineProperty
try { Object.defineProperty({}, 'x', {});
@@ -7,7 +7,7 @@ try { Object.defineProperty({}, 'x', {});
if (typeof window !== 'undefined' && window.__jstExtend__) {
var extend = window.__jstExtend__;
}
-else var extend = function(prototype, methods) {
+else var extend = function (prototype, methods) {
var title = null;
@@ -65,7 +65,7 @@ else var extend = function(prototype, methods) {
}
if (typeof module !== 'undefined' && module.exports) {
- module.exports.repl = function() {
+ module.exports.repl = function () {
var vm = require('vm'), repl = require('repl');
process.stdin.removeAllListeners('keypress');
var ctx = repl.start('toolkit> ').context;
@@ -99,8 +99,8 @@ if (typeof module !== 'undefined' && module.exports) {
else if (arguments.length === 0 || arrays.length === 0)
return [];
- return arrays.first().filter(function(val) {
- return arrays.every(function(arg) {
+ return arrays.first().filter(function (val) {
+ return arrays.every(function (arg) {
return arg.contains(val);
});
});
@@ -128,7 +128,7 @@ if (typeof module !== 'undefined' && module.exports) {
var vals = arrays.flatten(1);
- return vals.filter(function(a) {
+ return vals.filter(function (a) {
return vals.indexOf(a) == vals.lastIndexOf(a);
});
},
@@ -288,7 +288,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return false;
args = Array.prototype.slice.call(arguments);
- return args.every(function(arg) {
+ return args.every(function (arg) {
return !! ~ this.indexOf(arg);
}.bind(this));
},
@@ -310,7 +310,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return this;
exclude = Array.prototype.slice.call(arguments);
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return ! exclude.contains(val);
});
},
@@ -330,7 +330,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return this.clone();
exclude = Array.prototype.slice.call(arguments);
- return this.filter(function(val) {
+ return this.filter(function (val) {
return ! exclude.contains(val);
});
},
@@ -484,7 +484,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(a, idx) {
+ return this.filter(function (a, idx) {
return this.indexOf(a) == idx;
}.bind(this));
},
@@ -497,7 +497,7 @@ extend(Array.prototype, {
* @param callback The function to call on each item
* @param thisArg The value to assign to 'this' on the callback
* @example
- * [1,2,3,4,5,6].each(function(val, idx) {
+ * [1,2,3,4,5,6].each(function (val, idx) {
* if (val == 2) return idx;
* });
* // returns 2
@@ -526,7 +526,7 @@ extend(Array.prototype, {
if (level === undefined) level = -1;
else if (level == 0) return this.clone();
- return this.reduce(function(a,b) {
+ return this.reduce(function (a,b) {
return a.concat((Array.isArray(b) && level != 0) ? b.flatten(level - 1) : [b]);
}, []);
},
@@ -566,7 +566,7 @@ extend(Array.prototype, {
*
* @returns int
*/
- return this.reduce(function(a, b) {
+ return this.reduce(function (a, b) {
return Number(a) + Number(b);
});
},
@@ -582,7 +582,7 @@ extend(Array.prototype, {
*
* @returns int
*/
- return this.reduce(function(a, b) {
+ return this.reduce(function (a, b) {
return Number(a) * Number(b);
});
},
@@ -634,7 +634,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(val) {
+ return this.filter(function (val) {
return !! val;
});
},
@@ -652,7 +652,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return !! val;
});
},
@@ -666,7 +666,7 @@ extend(Array.prototype, {
* @param scope The value of this in the callback.
* @example
* var arr = [1,2,3,4,5,6];
- * arr.filter$(function(n) { return n.even() }) === arr; // true
+ * arr.filter$(function (n) { return n.even() }) === arr; // true
* arr;
* // arr = [2,4,6]
*
@@ -688,7 +688,7 @@ extend(Array.prototype, {
* @param scope The value of this in the callback.
* @example
* var arr = [1,2,3];
- * arr.map$(function(n) { return n * n }) === arr;
+ * arr.map$(function (n) { return n * n }) === arr;
* arr;
* // arr == [1,4,9]
*
@@ -713,7 +713,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.map(function(val) {
+ return this.map(function (val) {
return val[callback].apply(val, Array.prototype.slice.call(this, 1));
}, arguments);
},
@@ -733,7 +733,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.map$(function(val) {
+ return this.map$(function (val) {
return val[callback].apply(val, Array.prototype.slice.call(this, 1));
}, arguments);
},
@@ -758,7 +758,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.map(function(val) {
+ return this.map(function (val) {
if (Array.isArray(prop))
return Object.filter(val, prop);
@@ -789,7 +789,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.map$(function(val) {
+ return this.map$(function (val) {
if (Array.isArray(prop))
return Object.filter(val, prop);
@@ -809,7 +809,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(val) {
+ return this.filter(function (val) {
return !! val.match(regex);
});
},
@@ -827,7 +827,7 @@ extend(Array.prototype, {
* // arr = ['hello', 'cool']
* @returns self
*/
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return !! val.match(regex);
});
},
@@ -847,7 +847,7 @@ extend(Array.prototype, {
* @returns self
*/
var sorted = (typeof sort === 'function') ? this.sort(sort) : this.sort();
- sorted.forEach(function(val, i) {
+ sorted.forEach(function (val, i) {
this[i] = val;
}, this);
return this;
@@ -861,7 +861,7 @@ extend(Array.prototype, {
* @param mapping The mapping callback to apply to each value.
* @param [comparison] The comparison callback used in the sort afterwords.
* @example
- * ['hello','world','this','is','nice'].sortBy(function(s) { return s.length; }); // Sort by length
+ * ['hello','world','this','is','nice'].sortBy(function (s) { return s.length; }); // Sort by length
* // returns ['is', 'this', 'nice', 'hello', 'world']
*
* ['hello','world','this','is','nice'].sortBy('length');
@@ -873,16 +873,16 @@ extend(Array.prototype, {
return (typeof sort === 'function') ? this.sort(sort) : this.sort();
if (sort === undefined)
- sort = function(a,b) { return String(a) - String(b) };
+ sort = function (a,b) { return String(a) - String(b) };
// Get the values we intend to sort
- var arr = this[typeof cmp === 'function' ? 'map' : 'pluck'](cmp).map(function(val, i) {
+ var arr = this[typeof cmp === 'function' ? 'map' : 'pluck'](cmp).map(function (val, i) {
return { key: i, val: val };
});
- return arr.sort(function(a,b) {
+ return arr.sort(function (a,b) {
return sort(a.val, b.val);
- }).map(function(val) {
+ }).map(function (val) {
return this[val.key];
}, this);
},
@@ -902,7 +902,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- this.sortBy(cmp, sort).forEach(function(v, i) {
+ this.sortBy(cmp, sort).forEach(function (v, i) {
this[i] = v;
}, this);
@@ -922,7 +922,7 @@ extend(Array.prototype, {
* ['d','b','a','c','e'].fetch(2,1,3);
* // returns ['a','b','c']
*
- * [1,2,3,4,5,6].fetch(function(n,i) { return n % 6; });
+ * [1,2,3,4,5,6].fetch(function (n,i) { return n % 6; });
* // returns [6,1,2,3,4,5]
*
* @returns array
@@ -935,7 +935,7 @@ extend(Array.prototype, {
var arr = [];
- order.forEach(function(o, i) {
+ order.forEach(function (o, i) {
arr[o] = this[i];
}, this);
@@ -1137,10 +1137,10 @@ extend(Date, {
if (isNaN(Date.parse("2011-06-15T21:40:05+06:00"))) {
// XXX global assignment won't work in embeddings that use
// an alternate object for the context.
- Date = (function(NativeDate) {
+ Date = (function (NativeDate) {
// Date.length === 7
- var Date = function(Y, M, D, h, m, s, ms) {
+ var Date = function (Y, M, D, h, m, s, ms) {
var length = arguments.length;
if (this instanceof NativeDate) {
var date = length == 1 && String(Y) === Y ? // isString(Y)
@@ -1273,8 +1273,8 @@ if (isNaN(Date.parse("2011-06-15T21:40:05+06:00"))) {
funcs = funcs.reverse();
- return function(arg) {
- return funcs.reduce(function(a,b) {
+ return function (arg) {
+ return funcs.reduce(function (a,b) {
return b(a);
}, arg);
}
@@ -1292,7 +1292,7 @@ extend(Function.prototype, {
* @param time The number of milliseconds before deleting the cache.
* @param ident A callback used to map arguments to ids.
* @example
- * var fibonacci = function(n) {
+ * var fibonacci = function (n) {
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
* };
* // fibonacci(50) will take a several minutes to complete
@@ -1303,13 +1303,13 @@ extend(Function.prototype, {
* @returns function
*/
time = isNaN(time) ? -1 : time;
- ident = ident || function(id) {
+ ident = ident || function (id) {
return (typeof id == 'object') ? Object.id(id) : id.toString();
}
var cache = {}, callback = this, timeouts = {};
- return function() {
+ return function () {
var args = Array.prototype.slice.call(arguments), id = '(' + args.map(ident).join(',') + ')';
@@ -1320,7 +1320,7 @@ extend(Function.prototype, {
}
if (time > 0) {
- timeouts[id] = setTimeout(function() {
+ timeouts[id] = setTimeout(function () {
delete cache[id];
}, time);
}
@@ -1338,13 +1338,13 @@ extend(Function.prototype, {
* @param time The number of milliseconds before calling the function.
* @param scope The value of this within the callback.
* @example
- * Date.now.delay(function(now, then) {
+ * Date.now.delay(function (now, then) {
* log(now - then); // > 50 (Or very near it!)
* }, 50, Date.now());
*
* @returns function
*/
- return setTimeout(function(args) {
+ return setTimeout(function (args) {
callback.apply(scope, [this()].concat(Array.prototype.slice.call(args, 2)));
}.bind(this, arguments), time);
@@ -1358,7 +1358,7 @@ extend(Function.prototype, {
* @param scope Unfortunately the original function will loose it's scope. Re-add it here.
* @example
* function A() { this.foo = 'bar'; }
- * A.prototype.getFoo = function() { return this.foo; }
+ * A.prototype.getFoo = function () { return this.foo; }
*
* var obj = new A();
* obj.getFoo = obj.getFoo.once(); // INCORRECT! don't forget scope!
@@ -1376,7 +1376,7 @@ extend(Function.prototype, {
*/
var called = false, val = null;
- return function(args) {
+ return function (args) {
if ( ! called) {
called = true;
@@ -1396,7 +1396,7 @@ extend(Function.prototype, {
if ( ! Function.prototype.bind)
extend(Function.prototype, 'bind', function bind(thisArg) {
if ( ! Function.isFunction(this)) throw new TypeError(this + ' is not a function.');
- var args = Array.prototype.slice.call(arguments, 1), self = this, target = function() {};
+ var args = Array.prototype.slice.call(arguments, 1), self = this, target = function () {};
function bound() {
return self.apply(this instanceof target ? this : thisArg, args.concat(Array.prototype.slice.call(arguments)));
@@ -1433,7 +1433,7 @@ if ( ! Function.prototype.bind)
extend(Number.prototype, {
- chr: function() {
+ chr: function () {
/**
* Gets the current integer's representing string character.
*
@@ -1448,7 +1448,7 @@ extend(Number.prototype, {
},
- odd: function() {
+ odd: function () {
/**
* Determine's whether this integer is an odd number.
*
@@ -1463,7 +1463,7 @@ extend(Number.prototype, {
},
- even: function() {
+ even: function () {
/**
* Determine's whether this integer is an even number.
*
@@ -1490,7 +1490,7 @@ extend(Number.prototype, {
*
* @returns integer
*/
- return Array.prototype.slice.call(arguments).reduce(function(a, b) {
+ return Array.prototype.slice.call(arguments).reduce(function (a, b) {
if (a == 0 || b == 0)
return a | b;
@@ -1867,12 +1867,12 @@ extend(Number.prototype, {
if (('get' in desc ) || ('value' in desc)) {
delete desc['value'], delete desc['writable'];
- desc.get = function() {
+ desc.get = function () {
return object[property];
}
}
- desc.set = function(val) {
+ desc.set = function (val) {
return object[property] = val;
}
@@ -1896,7 +1896,7 @@ extend(Number.prototype, {
* @returns array
*/
var arr = [];
- Object.keys(obj).forEach(function(key) {
+ Object.keys(obj).forEach(function (key) {
arr.push(obj[key]);
});
@@ -1913,7 +1913,7 @@ extend(Number.prototype, {
* @param function The callback that takes parameters (key, value, object)
* @param scope The value of this in the callback function.
* @example
- * Object.forEach({1:2,3:4}, function(key, val, obj) {
+ * Object.forEach({1:2,3:4}, function (key, val, obj) {
* log(key + ':' + val)
* });
* // > 1:2
@@ -1921,7 +1921,7 @@ extend(Number.prototype, {
*
* @returns void
*/
- return Object.keys(obj).forEach(function(key) {
+ return Object.keys(obj).forEach(function (key) {
return callback.call(scope, key, obj[key], obj);
});
@@ -1937,7 +1937,7 @@ extend(Number.prototype, {
* Object.isObject({1:2,3:4});
* // returns true
*
- * Object.isObject(function() { });
+ * Object.isObject(function () { });
* // returns true
*
* Object.isObject(123, {});
@@ -1945,7 +1945,7 @@ extend(Number.prototype, {
*
* @returns bool
*/
- return Array.prototype.slice.call(arguments).every(function(value) {
+ return Array.prototype.slice.call(arguments).every(function (value) {
return Object(value) === value;
});
@@ -1960,7 +1960,7 @@ extend(Number.prototype, {
* @param function The callback that takes parameters (key, value, object)
* @param scope The value of this in the callback function.
* @example
- * var ret = Object.each({1:2,3:4}, function(key, val, obj) {
+ * var ret = Object.each({1:2,3:4}, function (key, val, obj) {
* return (key + ':' + val);
* });
* // ret = 1:2
@@ -1984,7 +1984,7 @@ extend(Number.prototype, {
* @param function The callback that takes parameters (value, key) and should return a new value
* @param scope The value of this in the callback function.
* @example
- * Object.map({1:2,3:4}, function(key, val) {
+ * Object.map({1:2,3:4}, function (key, val) {
* return key * val;
* });
* // returns {1:2,3:12}
@@ -2009,14 +2009,14 @@ extend(Number.prototype, {
* @param scope The value of this in the callback function.
* @example
* var obj = {1:2,3:4};
- * Object.map(obj, function(key, val) {
+ * Object.map(obj, function (key, val) {
* return key * val;
* });
* // obj = {1:2,3:12}
*
* @returns self
*/
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
Object.value(obj, key, callback.call(scope, key, val));
});
@@ -2050,7 +2050,7 @@ extend(Number.prototype, {
*/
var descriptors = {};
- Object.getOwnPropertyNames(object).forEach(function(key) {
+ Object.getOwnPropertyNames(object).forEach(function (key) {
descriptors[key] = Object.getOwnPropertyDescriptor(object, key);
});
@@ -2067,14 +2067,14 @@ extend(Number.prototype, {
* @param callback The function to call on each iteration
* @param [start=undefined] The initial value
* @example
- * Object.reduce({1:2,3:4}, function(group, key, val) {
+ * Object.reduce({1:2,3:4}, function (group, key, val) {
* return group + key + val;
* }, 0);
* // returns 10 (0+1+2+3+4)
*
* @returns mixed
*/
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
start = callback.call(scope, start, key, obj[key]);
});
@@ -2111,8 +2111,8 @@ extend(Number.prototype, {
level = (level === undefined) ? 0 : level;
- return objects.reduce(function(group, obj) {
- Object.forEach(obj, function(key, val) {
+ return objects.reduce(function (group, obj) {
+ Object.forEach(obj, function (key, val) {
if ( ! val in group || level == 0 || ! Object.isObject(group[key]) || ! Object.isObject(val)) {
group[key] = val;
}
@@ -2157,10 +2157,10 @@ extend(Number.prototype, {
var obj = Object.merge.apply(undefined, objects, level);
- Object.filter$(object, function(key, val) { return Object.hasOwnProperty.call(obj, key) });
- Object.map$(object, function(key, val) { return obj[key]; });
+ Object.filter$(object, function (key, val) { return Object.hasOwnProperty.call(obj, key) });
+ Object.map$(object, function (key, val) { return obj[key]; });
- Object.keys(obj).diff(Object.keys(object)).forEach(function(key) {
+ Object.keys(obj).diff(Object.keys(object)).forEach(function (key) {
Object.value(object, key, obj[key]);
});
@@ -2205,7 +2205,7 @@ extend(Number.prototype, {
* @param callback|array The callback to call on each property or an array of keys.
* @param scope The value of this in the callback function.
* @example
- * Object.filter({1:2,3:4,5:6}, function(key, val, object) {
+ * Object.filter({1:2,3:4,5:6}, function (key, val, object) {
* return key == 3;
* });
* // returns {3:4}
@@ -2230,7 +2230,7 @@ extend(Number.prototype, {
* @param scope The value of this in the callback function.
* @example
* var obj = {1:2,3:4,5:6};
- * Object.filter$(obj, function(key, val, object) {
+ * Object.filter$(obj, function (key, val, object) {
* return key == 3;
* });
* // obj = {3:4}
@@ -2243,7 +2243,7 @@ extend(Number.prototype, {
* @returns self
*/
if (Array.isArray(callback)) var keys = callback.invoke('toString');
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
if (Array.isArray(callback)) {
if ( ! keys.contains(key))
Object.remove(obj, key);
@@ -2268,7 +2268,7 @@ extend(Number.prototype, {
*
* @returns object
*/
- return Object.filter(obj, function(key, val) {
+ return Object.filter(obj, function (key, val) {
return !! val;
});
@@ -2287,7 +2287,7 @@ extend(Number.prototype, {
*
* @returns object
*/
- return Object.filter$(obj, function(key, val) {
+ return Object.filter$(obj, function (key, val) {
return !! val;
});
@@ -2326,7 +2326,7 @@ extend(Number.prototype, {
*/
var obj = {};
- keys.forEach(function(key, i) {
+ keys.forEach(function (key, i) {
obj[key] = values[i];
});
@@ -2367,7 +2367,7 @@ extend(Number.prototype, {
*/
return Object.defineProperties(object, {
- size: { value: function() {
+ size: { value: function () {
return Object.size(this);
}, writable: true, enumerable: false, configurable: true },
@@ -2509,7 +2509,7 @@ if ( ! Object.create) {
var object = {};
if (prototype !== null) {
- var type = function() {}
+ var type = function () {}
type.prototype = prototype;
object = new type();
}
@@ -2524,7 +2524,7 @@ if ( ! Object.create) {
}
if ( ! Object.defineProperty || domDefineProperty) {
- var oldDefineProperty = Object.defineProperty, definePropertyError = function(object, name, descriptor) {
+ var oldDefineProperty = Object.defineProperty, definePropertyError = function (object, name, descriptor) {
if ( ! Object.isObject(descriptor)) return 'Property description must be an object: ' + descriptor;
if ( ! Object.isObject(object)) return 'Object.defineProperty called on non-object';
@@ -2634,7 +2634,7 @@ if ( ! Object.keys)
for (key in object)
if (object.hasOwnProperty(key))
keys.push(key);
- keys = keys.filter(function(key) {
+ keys = keys.filter(function (key) {
return Object.prototype.propertyIsEnumerable.call(object, key);
});
@@ -2682,7 +2682,7 @@ if (domDefineProperty) {
*
* @returns string
*/
- return Array.range(0, 35).map(function(i) {
+ return Array.range(0, 35).map(function (i) {
switch (i) {
case 8:
case 13:
@@ -2834,7 +2834,7 @@ extend(String.prototype, {
*
* @returns string
*/
- return this.chars().map(function(a) {
+ return this.chars().map(function (a) {
return /[a-z]/.test(a) ? a.toUpperCase() : a.toLowerCase();
}).join('');
@@ -3005,7 +3005,7 @@ extend(String.prototype, {
*
* @returns string
*/
- this.chars().chunk(len).map(function(chars) {
+ this.chars().chunk(len).map(function (chars) {
return chars.join('');
});
},
@@ -3051,7 +3051,7 @@ extend(String.prototype, {
* // returns 'Hello World'
*/
var key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', output = '', input = this;
- return input.split("\n").map(function(line) {
+ return input.split("\n").map(function (line) {
var output = '';
for (i = 0; i < line.length; i += 4) {
var e1 = key.indexOf(line.charAt(i)),
@@ -3087,7 +3087,7 @@ extend(String.prototype, {
var vals = arguments, regex = /%%|%(?:(\d+)[\$#])?([+-])?('.|0| )?(\d*)(?:\.(\d+))?([bcdfosuxX])/g;
var index = 0;
- return this.replace(regex, function(substr, flags, align, padding, width, precision, type) {
+ return this.replace(regex, function (substr, flags, align, padding, width, precision, type) {
if (substr == '%%') return '%';
View
2  dist/jst.min.js
@@ -1 +1 @@
-(function(){var domDefineProperty=false,objectIdStore=[],objectDescriptorStore=[];try{Object.defineProperty({},"x",{})}catch(e){domDefineProperty=true}if(typeof window!=="undefined"&&window.__jstExtend__){var extend=window.__jstExtend__}else{var extend=function(prototype,methods){var title=null;switch(prototype){case Array:title="Array.";break;case Array.prototype:title="Array#";break;case Function:title="Function.";break;case Function.prototype:title="Function#";break;case Number:title="Number.";break;case Number.prototype:title="Number#";break;case Object:title="Object.";break;case Object.prototype:title="Object#";break;case String:title="String.";break;case String.prototype:title="String#";break;case Math:title="Math.";break;case Date:title="Date.";break;case Date.prototype:title="Date#";break;default:throw new Error("Override detector found an unknown prototype being extended.")}if(typeof methods==="string"){var n=methods,methods={};methods[n]=arguments[2]}for(name in methods){var method=methods[name];if(domDefineProperty){var id=-1;for(var i=0;i<objectIdStore.length;i++){if(objectIdStore[i]===prototype){id=i}}id=id<0?objectIdStore.push(prototype)-1:id;if(!objectDescriptorStore[id]){objectDescriptorStore[id]={}}objectDescriptorStore[id][name]={writable:true,enumerable:false,configurable:true};prototype[name]=method}else{Object.defineProperty(prototype,name,{value:method,writable:true,enumerable:false,configurable:true})}}}}if(typeof module!=="undefined"&&module.exports){module.exports.repl=function(){var vm=require("vm"),repl=require("repl");process.stdin.removeAllListeners("keypress");var ctx=repl.start("toolkit> ").context;ctx.Array=Array;ctx.Object=Object;ctx.Number=Number;ctx.Date=Date;ctx.RegExp=RegExp;ctx.String=String;ctx.Function=Function}}extend(Array,{intersect:function intersect(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}return arrays.first().filter(function(val){return arrays.every(function(arg){return arg.contains(val)})})},diff:function diff(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}var vals=arrays.flatten(1);return vals.filter(function(a){return vals.indexOf(a)==vals.lastIndexOf(a)})},union:function union(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}return Array.prototype.concat.apply([],arrays).unique()},range:function range(start,stop,step){if(arguments.length===1){stop=start;step=start=(stop<0?-1:1)}else{if(arguments.length===0){return[]}else{if(step===undefined){step=(stop<start?-1:1)}else{if(step===0||isNaN(step)){throw new RangeError("Step must be an valid integer and not be equal to 0.")}}}}step=Number(step),stop=Number(stop),start=Number(start);var arr=[];if(stop<start){if(step>=0){throw new RangeError("Stop must not be greater than start if step is to be positive.")}for(var i=start,arr=[];i>=stop;arr.push(i),i+=step){}}if(stop>start){if(step<=0){throw new RangeError("Stop must not be less than start if step is to be negative.")}for(var i=start,arr=[];i<=stop;arr.push(i),i+=step){}}return arr}});extend(Array.prototype,{concat$:function concat$(){var args=Array.prototype.slice.call(arguments).flatten(1);this.splice.apply(this,[this.length,0].concat(args));return this},swap:function swap(index1,index2){return this.clone().swap$(index1,index2)},swap$:function swap$(index1,index2){if(!Object.hasOwnProperty.call(this,Number(index1))){throw new RangeError("Array#swap: index1 does not exist within the array.")}if(!Object.hasOwnProperty.call(this,Number(index2))){throw new RangeError("Array#swap: index2 does not exist within the array.")}var value=this[index1];this[index1]=this[index2];this[index2]=value;return this},contains:function contains(values){if(arguments.length===0){return false}args=Array.prototype.slice.call(arguments);return args.every(function(arg){return !!~this.indexOf(arg)}.bind(this))},remove$:function remove$(){if(arguments.length===0){return this}exclude=Array.prototype.slice.call(arguments);return this.filter$(function(val){return !exclude.contains(val)})},remove:function remove(){if(arguments.length===0){return this.clone()}exclude=Array.prototype.slice.call(arguments);return this.filter(function(val){return !exclude.contains(val)})},shuffle:function shuffle(){var arr=this.clone();for(var index=0;index<arr.length-1;index++){arr.swap$(index,Number.random(index,arr.length-1).round())}return arr},shuffle$:function shuffle$(){for(var index=0;index<this.length-1;index++){this.swap$(index,Number.random(index,this.length-1).round())}return this},clone:function clone(){return this.slice()},intersect:function intersect(){return Array.intersect(Array.prototype.slice.call(arguments).concat([this]))},diff:function diff(){return Array.diff(Array.prototype.slice.call(arguments).concat([this]))},union:function union(){return Array.union(Array.prototype.slice.call(arguments).concat([this]))},chunk:function chunk(size){for(var arr=[];this.length>0;arr.push(this.splice(0,size))){}return arr},chunk$:function chunk$(size){for(var i=0,length=this.length/size;i<length;i++){this.splice(i,0,this.splice(i,size))}return this},unique:function unique(){return this.filter(function(a,idx){return this.indexOf(a)==idx}.bind(this))},each:function each(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=[],result;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&(result=callback.call(thisArg,self[i],i,self))!==undefined){return result}}},flatten:function flatten(level){if(level===undefined){level=-1}else{if(level==0){return this.clone()}}return this.reduce(function(a,b){return a.concat((Array.isArray(b)&&level!=0)?b.flatten(level-1):[b])},[])},flatten$:function flatten$(level){if(level===undefined){level=-1}for(var i=0,length=this.length;i<length;i++){if(Array.isArray(this[i])&&level!=0){this.splice.apply(this,[i,1].concat(this[i].flatten(level-1)))}}return this},sum:function sum(){return this.reduce(function(a,b){return Number(a)+Number(b)})},product:function product(){return this.reduce(function(a,b){return Number(a)*Number(b)})},first:function first(num){return num?this.slice(0,num||1):this[0]},last:function last(num){return num?this.slice(this.length-(num||1)):this[this.length-1]},clean:function clean(){return this.filter(function(val){return !!val})},clean$:function clean$(){return this.filter$(function(val){return !!val})},filter$:function filter$(callback,scope){for(var i=0;i<this.length;i++){if(!callback.call(scope,this[i],i,this)){this.splice(i,1)&&i--}}return this},map$:function map$(callback,scope){for(var i=0;i<this.length;i++){this[i]=callback.call(scope,this[i],i,this)}return this},invoke:function invoke(callback){return this.map(function(val){return val[callback].apply(val,Array.prototype.slice.call(this,1))},arguments)},invoke$:function invoke$(callback){return this.map$(function(val){return val[callback].apply(val,Array.prototype.slice.call(this,1))},arguments)},pluck:function pluck(prop){return this.map(function(val){if(Array.isArray(prop)){return Object.filter(val,prop)}return val[prop]})},pluck$:function pluck$(prop){return this.map$(function(val){if(Array.isArray(prop)){return Object.filter(val,prop)}return val[prop]})},grep:function grep(regex){return this.filter(function(val){return !!val.match(regex)})},grep$:function grep$(regex){return this.filter$(function(val){return !!val.match(regex)})},sort$:function sort$(sort){var sorted=(typeof sort==="function")?this.sort(sort):this.sort();sorted.forEach(function(val,i){this[i]=val},this);return this},sortBy:function sortBy(cmp,sort){if(cmp===undefined){return(typeof sort==="function")?this.sort(sort):this.sort()}if(sort===undefined){sort=function(a,b){return String(a)-String(b)}}var arr=this[typeof cmp==="function"?"map":"pluck"](cmp).map(function(val,i){return{key:i,val:val}});return arr.sort(function(a,b){return sort(a.val,b.val)}).map(function(val){return this[val.key]},this)},sortBy$:function sortBy$(cmp,sort){this.sortBy(cmp,sort).forEach(function(v,i){this[i]=v},this);return this},fetch:function fetch(order){if(typeof order=="function"){order=this.map(order)}if(!Array.isArray(order)){order=Array.prototype.slice.call(arguments)}var arr=[];order.forEach(function(o,i){arr[o]=this[i]},this);return arr}});if(!Array.isArray){extend(Array,"isArray",function isArray(arr){return Object.prototype.toString.call(arr)==="[object Array]"})}if(!Array.prototype.forEach){extend(Array.prototype,"forEach",function forEach(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if(i in self){callback.call(thisArg,self[i],i,self)}}})}if(!Array.prototype.map){extend(Array.prototype,"map",function map(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=new Array(length);if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if(i in self){arr[i]=callback.call(thisArg,self[i],i,self)}}return arr})}if(!Array.prototype.filter){extend(Array.prototype,"filter",function filter(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=[];if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&callback.call(thisArg,self[i],i,self)){arr.push(self[i])}}return arr})}if(!Array.prototype.every){extend(Array.prototype,"every",function every(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&!callback.call(thisArg,self[i],i,self)){return false}}return true})}if(!Array.prototype.some){extend(Array.prototype,"some",function some(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&callback.call(thisArg,self[i],i,self)){return true}}return false})}if(!Array.prototype.reduce){extend(Array.prototype,"reduce",function reduce(callback){var self=Object(this),value=arguments[1],length=this.length>>>0,i=0,j=i;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}if(arguments.length<=1){if(!length){throw new TypeError("Reduce of empty array with no initial value.")}for(i=-1;j<self.length;j++){if(Object.hasOwnProperty.call(self,String(j))){i=j;break}}if(i===-1){throw new TypeError("Reduce of empty array with no initial value.")}value=self[i++]}for(;i<length;i++){if(Object.hasOwnProperty.call(self,i)){value=callback.call(undefined,value,self[i],i,self)}}return value})}if(!Array.prototype.reduceRight){extend(Array.prototype,"reduceRight",function reduceRight(callback){var self=Object(this),value=arguments[1],length=this.length>>>0,i=length-1,j=i;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}if(arguments.length<=1){if(!length){throw new TypeError("Array length is 0 and no initial value given.")}for(i=-1;j>=0;j--){if(Object.hasOwnProperty.call(self,String(j))){i=j;break}}if(i===-1){throw new TypeError("Reduce of empty array with no initial value.")}value=self[i--]}for(;i>=0;i--){if(Object.hasOwnProperty.call(self,i)){value=callback.call(undefined,value,self[i],i,self)}}return value})}if(!Array.prototype.indexOf){extend(Array.prototype,"indexOf",function indexOf(value){var self=Object(this),length=this.length>>>0,index=(arguments.length<=1)?0:Number(arguments[1]);index=index<0?length-Math.abs(index):index;for(var i=index;i<length;i++){if((i in self)&&self[i]===value){return i}}return -1})}if(!Array.prototype.lastIndexOf){extend(Array.prototype,"lastIndexOf",function lastIndexOf(value){if(this===void 0||this===null){throw new TypeError()}var self=Object(this),length=this.length>>>0,index=length;if(length===0){return -1}if(arguments.length>1){index=Number(arguments[1]);if(index!==index){index=0}else{if(index!==0&&index!==(1/0)&&index!==-(1/0)){index=(index>0||-1)*Math.floor(Math.abs(index))}}}var i=(index>=0)?Math.min(index,length-1):length-Math.abs(index);for(;i>=0;i--){if((i in self)&&(self[i]===value)){return i}}return -1})}extend(Date.prototype,{fuzzyDiff:function fuzzyDiff(date,suffix,prefix){if(!(date instanceof Date)){date=new Date(date)}var delta=this.getTime()-date.getTime();var units={second:1000,minute:60000,hour:3600000,day:86400000,year:31557600000};var keys=Object.keys(units),divs=Object.values(units);for(var i=0;i<divs.length;i++){if((delta/divs[i])<1){var time=(delta/divs[i-1]),key=keys[i-1];if(time>1){key+="s"}if(arguments.length<3){prefix=(time.round()==time)?"exactly":"about"}if(arguments.length<2){suffix="ago"}return"%s %d %s %s".sprintf(prefix,time.round(),key,suffix)}}}});if(!Date.now){extend(Date,"now",function now(){return(new Date()).getTime()})}extend(Date,{SECOND:1,MINUTE:60,HOUR:3600,DAY:86400,YEAR:31557600,DECADE:315576000});if(isNaN(Date.parse("2011-06-15T21:40:05+06:00"))){Date=(function(NativeDate){var Date=function(Y,M,D,h,m,s,ms){var length=arguments.length;if(this instanceof NativeDate){var date=length==1&&String(Y)===Y?new NativeDate(Date.parse(Y)):length>=7?new NativeDate(Y,M,D,h,m,s,ms):length>=6?new NativeDate(Y,M,D,h,m,s):length>=5?new NativeDate(Y,M,D,h,m):length>=4?new NativeDate(Y,M,D,h):length>=3?new NativeDate(Y,M,D):length>=2?new NativeDate(Y,M):length>=1?new NativeDate(Y):new NativeDate();date.constructor=Date;return date}return NativeDate.apply(this,arguments)};var isoDateExpression=new RegExp("^(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:Z|(?:([-+])(\\d{2}):(\\d{2})))?)?)?)?$");for(var key in NativeDate){Date[key]=NativeDate[key]}Date.now=NativeDate.now;Date.UTC=NativeDate.UTC;Date.prototype=NativeDate.prototype;Date.prototype.constructor=Date;Date.parse=function parse(string){var match=isoDateExpression.exec(string);if(match){match.shift();for(var i=1;i<7;i++){match[i]=+(match[i]||(i<3?1:0));if(i==1){match[i]--}}var minutesOffset=+match.pop(),hourOffset=+match.pop(),sign=match.pop();var offset=0;if(sign){if(hourOffset>23||minuteOffset>59){return NaN}offset=(hourOffset*60+minuteOffset)*60000*(sign=="+"?-1:1)}return NativeDate.UTC.apply(this,match)+offset}return NativeDate.parse.apply(this,arguments)};return Date})(Date)}extend(Function,{isFunction:function compose(func){return(typeof func==="function")&&func.call},compose:function compose(funcs){if(!Array.isArray(funcs)){funcs=Array.prototype.slice.call(arguments)}funcs=funcs.reverse();return function(arg){return funcs.reduce(function(a,b){return b(a)},arg)}}});extend(Function.prototype,{cache:function cache(time,ident){time=isNaN(time)?-1:time;ident=ident||function(id){return(typeof id=="object")?Object.id(id):id.toString()};var cache={},callback=this,timeouts={};return function(){var args=Array.prototype.slice.call(arguments),id="("+args.map(ident).join(",")+")";if(!(id in cache)){cache[id]=callback.apply(callback,args)}else{if(id in timeouts){clearTimeout(timeouts[id]);delete timeouts[id]}}if(time>0){timeouts[id]=setTimeout(function(){delete cache[id]},time)}return cache[id]}},delay:function delay(callback,time,scope){return setTimeout(function(args){callback.apply(scope,[this()].concat(Array.prototype.slice.call(args,2)))}.bind(this,arguments),time)},once:function once(scope){var called=false,val=null;return function(args){if(!called){called=true;val=this.apply(scope,args)}return val}.bind(this,Array.prototype.slice.call(arguments))}});if(!Function.prototype.bind){extend(Function.prototype,"bind",function bind(thisArg){if(!Function.isFunction(this)){throw new TypeError(this+" is not a function.")}var args=Array.prototype.slice.call(arguments,1),self=this,target=function(){};function bound(){return self.apply(this instanceof target?this:thisArg,args.concat(Array.prototype.slice.call(arguments)))}target.prototype=this.prototype;bound.prototype=new target();return bound})}extend(Number,{random:function random(start,end){return(start=start||0)+(((end||start+1)-start)*Math.random())}});extend(Number.prototype,{chr:function(){return String.fromCharCode(this)},odd:function(){return !this.even()},even:function(){return(this%2)==0},gcd:function gcd(){return Array.prototype.slice.call(arguments).reduce(function(a,b){if(a==0||b==0){return a|b}for(var shift=0;((a|b)&1)==0;shift++){a>>=1;b>>=1}while((a&1)==0){a>>=1}do{while((b&1)==0){b>>=1}if(a<b){b-=a}else{var diff=a-b;a=b;b=diff}b>>=1}while(b!=0);return a<<shift},this)},lcm:function lcm(){var nums=Array.prototype.slice.call(arguments),gcd=this.gcd.apply(this,nums);return Math.abs(nums.product()*this)/gcd},ceil:function ceil(){return Math.ceil(this)},floor:function floor(){return Math.floor(this)},abs:function abs(){return Math.abs(this)},round:function round(digits){digits=digits||0;if(digits==0){return Math.round(this)}else{if(digits<0){return Number(this.toPrecision(this.floor().toString().length-digits.abs()))}else{return Number(this.toFixed(digits))}}},radix:function radix(base,size,character){return this.toString(base).pad(-size,(character||"0"))},bin:function bin(size,character){return this.radix(2,size,character)},oct:function oct(size,character){return this.radix(8,size,character)},dec:function dec(size,character){return this.radix(10,size,character)},hexl:function hexl(size,character){return this.radix(16,size,character)},hex:function hex(size,character){return this.radix(16,size,character).toUpperCase()},abbr:function abbr(digits,binary){binary=!!(binary==undefined?false:binary);var prefixes={k:binary?1<<10:1000,M:binary?1<<20:1000000,G:binary?1<<30:1000000000,T:binary?Math.pow(2,40):1000000000000,P:binary?Math.pow(2,50):1000000000000000,E:binary?Math.pow(2,60):1000000000000000000,Z:binary?Math.pow(2,70):1e+21,Y:binary?Math.pow(2,80):1e+24};var keys=Object.keys(prefixes),divs=Object.values(prefixes);if(divs[0]>this){return this.toFixed(digits)}for(var i=0;i<divs.length;i++){if((this/divs[i])<1){return(this/divs[i-1]).toFixed(digits)+keys[i-1]}}return(this/divs.last()).toFixed(digits)+keys.last()}});extend(Object,{value:function set(obj,key){var desc=Object.getOwnPropertyDescriptor(obj,key);if(desc&&!Object.getOwnPropertyDescriptor(obj,key).writable){return obj[key]}return(arguments.length===2)?obj[key]:(obj[key]=arguments[2])},remove:function remove(obj,key){if(!Object.getOwnPropertyDescriptor(obj,key).configurable){return false}if(obj.__ownPropertyDescriptors__){delete obj.__ownPropertyDescriptors__[key]}return delete obj[key]},id:function id(obj){if(!objectIdStore.contains(obj)){objectIdStore.push(obj)}return objectIdStore.indexOf(obj)},alias:function alias(object,property,alias,complete){var desc=Object.getOwnPropertyDescriptor(object,property);if(!complete){Object.defineProperty(object,alias,desc)}else{if(("get" in desc)||("value" in desc)){delete desc.value,delete desc.writable;desc.get=function(){return object[property]}}desc.set=function(val){return object[property]=val};Object.defineProperty(object,alias,desc)}return object},values:function values(obj){var arr=[];Object.keys(obj).forEach(function(key){arr.push(obj[key])});return arr},forEach:function forEach(obj,callback,scope){return Object.keys(obj).forEach(function(key){return callback.call(scope,key,obj[key],obj)})},isObject:function isObject(){return Array.prototype.slice.call(arguments).every(function(value){return Object(value)===value})},each:function each(obj,callback,scope){var key,result;for(key in obj){if(key!=="__proto__"){if((result=callback.call(scope,key,obj[key],this))!==undefined){return result}}}},map:function map(object,callback,scope){var obj=Object.clone(object);Object.map$(obj,callback,scope);return obj},map$:function map$(obj,callback,scope){Object.forEach(obj,function(key,val){Object.value(obj,key,callback.call(scope,key,val))});return obj},getOwnPropertyDescriptors:function getOwnPropertyDescriptors(object){var descriptors={};Object.getOwnPropertyNames(object).forEach(function(key){descriptors[key]=Object.getOwnPropertyDescriptor(object,key)});return descriptors},reduce:function reduce(obj,callback,start,scope){Object.forEach(obj,function(key,val){start=callback.call(scope,start,key,obj[key])});return start},merge:function merge(objects,level){if(Object.isObject(objects,level)){objects=Array.prototype.slice.call(arguments),level=0}level=(level===undefined)?0:level;return objects.reduce(function(group,obj){Object.forEach(obj,function(key,val){if(!val in group||level==0||!Object.isObject(group[key])||!Object.isObject(val)){group[key]=val}else{group[key]=Object.merge([group[key],val],level-1)}});return group},{})},merge$:function merge$(object,objects,level){if(Array.isArray(objects)){objects=[object].concat(objects)}else{objects=Array.prototype.slice.call(arguments);level=undefined}var obj=Object.merge.apply(undefined,objects,level);Object.filter$(object,function(key,val){return Object.hasOwnProperty.call(obj,key)});Object.map$(object,function(key,val){return obj[key]});Object.keys(obj).diff(Object.keys(object)).forEach(function(key){Object.value(object,key,obj[key])});return object},clone:function clone(obj,inherit){inherit=(inherit===undefined)?true:false;var obj=Object.create(Object.getPrototypeOf(obj),inherit?Object.getOwnPropertyDescriptors(obj):undefined);return obj},filter:function filter(object,callback,scope){return Object.filter$(Object.clone(object),callback,scope)},filter$:function filter$(obj,callback,scope){if(Array.isArray(callback)){var keys=callback.invoke("toString")}Object.forEach(obj,function(key,val){if(Array.isArray(callback)){if(!keys.contains(key)){Object.remove(obj,key)}}else{if(callback.call(scope,key,val,obj)===false){Object.remove(obj,key)}}});return obj},clean:function clean(obj){return Object.filter(obj,function(key,val){return !!val})},clean$:function clean$(obj){return Object.filter$(obj,function(key,val){return !!val})},size:function size(obj){return Object.keys(obj).length},combine:function combine(keys,values){var obj={};keys.forEach(function(key,i){obj[key]=values[i]});return obj},hash:function hash(object){return Object.hash$(Object.clone(object))},hash$:function hash$(object){return Object.defineProperties(object,{size:{value:function(){return Object.size(this)},writable:true,enumerable:false,configurable:true},keys:{value:function keys(callback,scope){return Object.keys(this)},writable:true,enumerable:false,configurable:true},each:{value:function each(callback,scope){return Object.each(this,callback,scope)},writable:true,enumerable:false,configurable:true},forEach:{value:function forEach(callback,scope){return Object.forEach(this,callback,scope)},writable:true,enumerable:false,configurable:true},map:{value:function map(callback,scope){return Object.map(this,callback,scope)},writable:true,enumerable:false,configurable:true},map$:{value:function map$(callback,scope){return Object.map$(this,callback,scope)},writable:true,enumerable:false,configurable:true},reduce:{value:function reduce(callback,start){return Object.reduce(this,callback,start)},writable:true,enumerable:false,configurable:true},filter:{value:function filter(callback,scope){return Object.filter(this,callback,scope)},writable:true,enumerable:false,configurable:true},filter$:{value:function filter$(callback,scope){return Object.filter$(this,callback,scope)},writable:true,enumerable:false,configurable:true},clean:{value:function clean(callback,scope){return Object.clean(this,callback,scope)},writable:true,enumerable:false,configurable:true},clean$:{value:function clean$(callback,scope){return Object.clean$(this,callback,scope)},writable:true,enumerable:false,configurable:true},clone:{value:function clone(callback,scope){return Object.clone(this,callback,scope)},writable:true,enumerable:false,configurable:true},merge:{value:function merge(){return Object.merge.apply(undefined,[this].concat(Array.prototype.slice.call(arguments)))},writable:true,enumerable:false,configurable:true},merge$:{value:function merge$(){return Object.merge$.apply(undefined,[this].concat(Array.prototype.slice.call(arguments)))},writable:true,enumerable:false,configurable:true}})}});if(!Object.getPrototypeOf){extend(Object,"getPrototypeOf",function getPrototypeOf(object){return object.__proto__||object.constructor.prototype||protoStore[Object.id(object)]})}if(!Object.getOwnPropertyDescriptor||domDefineProperty){var oldGetOwnPropertyDescriptor=Object.getOwnPropertyDescriptor,objectDescriptorStore={};extend(Object,"getOwnPropertyDescriptor",function getOwnPropertyDescriptor(object,property){if(object.nodeType&&oldGetOwnPropertyDescriptor){return oldGetOwnPropertyDescriptor(object,property)}if(!Object.isObject(object)){throw new TypeError(object+" is not an object.")}if(!Object.prototype.hasOwnProperty.call(object,property)){return}var descriptor={enumerable:true,writable:true,configurable:true},getter,setter,id=Object.id(object);if((object===Number&&["NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","MAX_VALUE","MIN_VALUE"].contains(property))||(object===Math&&["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2"].contains(property))||(object instanceof Function&&["arguments","length","name","prototype","caller"].contains(property))){descriptor={configurable:false,writable:false,enumerable:false}}if((object===Math&&["cos","pow","log","tan","sqrt","ceil","asin","abs","max","exp","atan2","random","round","floor","acos","atan","min","sin"].contains(property))||(object===String&&property==="fromCharCode")){descriptor={configurable:true,writable:true,enumerable:false}}if(object instanceof RegExp&&["lastIndex","multiline","global","source","ignoreCase"].contains(property)){descriptor={configurable:false,writable:(property=="lastIndex"),enumerable:false}}if((Array.isArray(object)||String.isString(object))&&property==="length"){descriptor={configurable:false,writable:true,enumerable:false}}else{if(objectDescriptorStore[id]&&(property in objectDescriptorStore[id])){descriptor=objectDescriptorStore[id][property]}}if(descriptor.writable===false){if(Object.prototype.__lookupGetter__&&(getter=object.__lookupGetter__(property))){descriptor.writable=false;descriptor.get=getter}if(Object.prototype.__lookupSetter__&&(setter=object.__lookupSetter__(property))){descriptor.writable=false;descriptor.set=setter}}if(!("set" in descriptor||"get" in descriptor)){descriptor.value=object[property]}return descriptor})}if(!Object.getOwnPropertyNames){extend(Object,"getOwnPropertyNames",function getOwnPropertyNames(object){var names=[];if(object===Number){names=["NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","MAX_VALUE","MIN_VALUE"]}else{if(object===Math){names=["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2","cos","pow","log","tan","sqrt","ceil","asin","abs","max","exp","atan2","random","round","floor","acos","atan","min","sin"]}else{if(object===String){names=["fromCharCode"]}}}if(object instanceof RegExp){names.push.apply(names,["lastIndex","multiline","global","source","ignoreCase"])}else{if(object instanceof Function){names.push.apply(names,["arguments","length","name","prototype","caller"])}else{if(Array.isArray(object)||String.isString(object)){names.push("length")}else{if(Object.prototype.hasOwnProperty.call(object,"constructor")){names.push("constructor")}}}}return names.concat(Object.keys(objectDescriptorStore[Object.id(object)]||{})).concat(Object.keys(object)).unique()})}if(!Object.create){var protoStore=[];extend(Object,"create",function create(prototype,descriptors){if(prototype!==null&&Object(prototype)!==prototype){throw new TypeError("Object prototype may only be an Object or null")}var object={};if(prototype!==null){var type=function(){};type.prototype=prototype;object=new type()}if(descriptors!==undefined){Object.defineProperties(object,descriptors)}if(object.__proto__!==undefined){object.__proto__=prototype}else{protoStore[Object.id(object)]=prototype}return object})}if(!Object.defineProperty||domDefineProperty){var oldDefineProperty=Object.defineProperty,definePropertyError=function(object,name,descriptor){if(!Object.isObject(descriptor)){return"Property description must be an object: "+descriptor}if(!Object.isObject(object)){return"Object.defineProperty called on non-object"}if("get" in descriptor){if(!object.__defineGetter__){return"Getters are not supported on this javascript engine."}if(!Function.isFunction(descriptor.get)){return"Getter must be a function: "+descriptor.get}}if("set" in descriptor){if(!object.__defineSetter__){return"Setters are not supported on this javascript engine."}if(!Function.isFunction(descriptor.set)){return"Setter must be a function: "+descriptor.get}}if(("get" in descriptor||"set" in descriptor)&&("value" in descriptor||descriptor.writable)){return"A property cannot both have accessors and be writable or have a value: "+object}};extend(Object,"defineProperty",function defineProperty(object,name,descriptor){if(object.nodeType&&oldDefineProperty){oldDefineProperty(object,name,descriptor)}var id=Object.id(object),error,prototype;if((error=definePropertyError(object,name,descriptor))){throw new TypeError(error)}if(object.__defineGetter__){if((name in object)&&(object.__lookupGetter__(name))){prototype=object.__proto__;object.__proto__=Object.prototype;delete object[name]}if("get" in descriptor){object.__defineGetter__(name,descriptor.get)}if("set" in descriptor){object.__defineSetter__(name,descriptor.set)}}if(!objectDescriptorStore[id]){objectDescriptorStore[id]={}}if(!descriptor.writable){descriptor.writable=false}if(!descriptor.configurable){descriptor.configurable=false}if(!descriptor.enumerable){descriptor.enumerable=false}if(!("get" in descriptor||"set" in descriptor)){object[name]=descriptor.value}objectDescriptorStore[id][name]=descriptor;if(prototype){object.__proto__=prototype}return object})}if(!Object.defineProperties||domDefineProperty){extend(Object,"defineProperties",function defineProperties(object,descriptors){if(!Object.isObject(object)){throw new TypeError("Object.defineProperties called on non-object")}var name,error;for(name in descriptors){if(error=definePropertyError(object,name,descriptors[name])){throw new TypeError(error)}}for(name in descriptors){Object.defineProperty(object,name,descriptors[name])}return object})}if(!Object.seal){var sealedStore=[]}extend(Object,"seal",function seal(object){if(!Object.isObject(object)){throw new TypeError("Object.seal called on non-object")}sealedStore[Object.id(object)]=true;return object});if(!Object.isSealed){extend(Object,"isSealed",function isSealed(object){if(!Object.isObject(object)){throw new TypeError("Object.isSealed called on non-object")}return !!sealedStore[Object.id(object)]})}if(!Object.freeze){var frozenStore=[]}extend(Object,"freeze",function freeze(object){if(!Object.isObject(object)){throw new TypeError("Object.freeze called on non-object")}frozenStore[Object.id(object)]=true;return object});if(!Object.isFrozen){extend(Object,"isFrozen",function isFrozen(object){if(!Object.isObject(object)){throw new TypeError("Object.isFrozen called on non-object")}return !!frozenStore[Object.id(object)]})}if(!Object.preventExtensions){var preventExtensionsStore=[]}extend(Object,"preventExtensions",function preventExtensions(object){if(!Object.isObject(object)){throw new TypeError("Object.preventExtensions called on non-object")}preventExtensionsStore[Object.id(object)]=true;return object});if(!Object.isExtensible){extend(Object,"isExtensible",function isExtensible(object){if(!Object.isObject(object)){throw new TypeError("Object.isExtensible called on non-object")}var id=Object.id(object);return !preventExtensionsStore[id]&&!sealedStore[id]})}if(!Object.keys){extend(Object,"keys",function keys(object){if(object!==Object(object)){throw new TypeError("Object.keys called on non-object")}var keys=[],key;for(key in object){if(object.hasOwnProperty(key)){keys.push(key)}}keys=keys.filter(function(key){return Object.prototype.propertyIsEnumerable.call(object,key)});if(String.isString(object)&&!(0 in (new String(" ")))){keys=keys.concat(Array.range(0,object.length-1))}return keys.map(String)})}if(domDefineProperty){var oldPropertyIsEnumerable=Object.prototype.propertyIsEnumerable;Object.prototype.propertyIsEnumerable=function propertyIsEnumerable(key){var desc=objectDescriptorStore[Object.id(this)];if(desc&&desc[key]){return desc[key].enumerable===true}else{if(oldPropertyIsEnumerable){oldPropertyIsEnumerable.call(this,key)}else{for(var name in this){if(name==key){return true}}}}return true}}extend(String,{isString:function isString(object){return typeof object==="string"||object instanceof String},UUID:function UUID(){return Array.range(0,35).map(function(i){switch(i){case 8:case 13:case 23:return"-";case 14:i=4;break;case 19:i=(Number.random(0,16).floor()&3)|8;break;default:i=Number.random(0,16).floor();break}return"0123456789ABCDEF".charAt(i)}).join("")}});extend(String.prototype,{repeat:function repeat(num){var str="";for(var i=0,str="";i<(num||1);i++){str+=this}return str},chars:function chars(){for(var i=0,arr=[];i<this.length;i++){arr.push(this.charAt(i))}return arr},count:function count(substr,mod){return this.match(RegExp(substr,mod||"gi")).length},insert:function insert(substr,pos){return this.substr(0,pos||0)+substr+this.substr(pos||0)},remove:function remove(substr){return this.replace(substr,"")},reverse:function reverse(){return this.chars().reverse().join("")},ucfirst:function ucfirst(){return this.charAt(0).toUpperCase()+this.substr(1)},swapcase:function swapcase(){return this.chars().map(function(a){return/[a-z]/.test(a)?a.toUpperCase():a.toLowerCase()}).join("")},rpad:function rpad(len,chars){len=Number(len);if(len<this.length){return this.valueOf()}for(var str=this;str.length<len;str+=(chars||" ")){}return str.substr(0,len)},lpad:function lpad(len,chars){len=Number(len);if(len<this.length){return this.valueOf()}chars=(chars||" ").reverse();for(var str=this;str.length<len;str=(chars+str)){}return str.substr(str.length-len)},pad:function pad(len,chars){return this[len>0?"rpad":"lpad"](Math.abs(len),chars)},soundex:function soundex(){return this.substr(0,1).toUpperCase()+this.toUpperCase().substr(1).remove(/[^A-Z]/gi).trim().replace(/DG/g,"G").replace(/GH/g,"H").replace(/GN|KN/g,"N").replace(/PH/g,"F").replace(/MP([STZ])/g,"M$1").replace(/^PS/g,"S").replace(/^PF/g,"F").replace(/MB/g,"M").replace(/TCH/g,"CH").replace(/[AEIOUHWY]/g,"0").replace(/[BFPV]/g,"1").replace(/[CGJKQSXZ]/g,"2").replace(/[DT]/g,"3").replace(/[L]/g,"4").replace(/[MN]/g,"5").replace(/[R]/g,"6").replace(/(\w)\1+/g,"$1").slice(0,3).rpad(3,"0")},distance:function distance(c){var s,l=(s=this.split("")).length,t=(c=c.split("")).length,i,j,m,n;if(!(l||t)){return Math.max(l,t)}for(var a=[],i=l+1;i;a[--i]=[i]){}for(i=t+1;a[0][--i]=i;){}for(i=-1,m=s.length;++i<m;){for(j=-1,n=c.length;++j<n;){a[(i*=1)+1][(j*=1)+1]=Math.min(a[i][j+1]+1,a[i+1][j]+1,a[i][j]+(s[i]!=c[j]))}}return a[l][t]},soundex:function soundex(){return this.substr(0,1).toUpperCase()+this.toUpperCase().substr(1).remove(/[^A-Z]/gi).trim().replace(/DG/g,"G").replace(/GH/g,"H").replace(/GN|KN/g,"N").replace(/PH/g,"F").replace(/MP([STZ])/g,"M$1").replace(/^PS/g,"S").replace(/^PF/g,"F").replace(/MB/g,"M").replace(/TCH/g,"CH").replace(/[AEIOUHWY]/g,"0").replace(/[BFPV]/g,"1").replace(/[CGJKQSXZ]/g,"2").replace(/[DT]/g,"3").replace(/[L]/g,"4").replace(/[MN]/g,"5").replace(/[R]/g,"6").replace(/(\w)\1+/g,"$1").rpad(3,"0")},chunk:function chunk(len){this.chars().chunk(len).map(function(chars){return chars.join("")})},btoa:function btoa(){if(typeof window!=="undefined"&&window.btoa){return window.btoa(this)}var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",output="",input=this.valueOf();for(i=0;i<input.length;i+=3){var c1=input.charCodeAt(i),c2=input.charCodeAt(i+1),c3=input.charCodeAt(i+2);var e1=c1>>2,e2=((c1&3)<<4)|(c2>>4),e3=((c2&15)<<2)|(c3>>6),e4=c3&63;if(isNaN(c1)){e3=e4=64}else{if(isNaN(c3)){e4=64}}output+=key.charAt(e1)+key.charAt(e2)+key.charAt(e3)+key.charAt(e4)}return output},atob:function atob(){var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",output="",input=this;return input.split("\n").map(function(line){var output="";for(i=0;i<line.length;i+=4){var e1=key.indexOf(line.charAt(i)),e2=key.indexOf(line.charAt(i+1)),e3=key.indexOf(line.charAt(i+2)),e4=key.indexOf(line.charAt(i+3));var c1=(e1<<2)|(e2>>4),c2=((e2&15)<<4)|(e3>>2),c3=((e3&3)<<6)|e4;output+=String.fromCharCode(c1);if(e3!=64){output+=String.fromCharCode(c2)}if(e4!=64){output+=String.fromCharCode(c3)}}return output}).join("")},sprintf:function sprintf(c){var vals=arguments,regex=/%%|%(?:(\d+)[\$#])?([+-])?('.|0| )?(\d*)(?:\.(\d+))?([bcdfosuxX])/g;var index=0;return this.replace(regex,function(substr,flags,align,padding,width,precision,type){if(substr=="%%"){return"%"}flags=flags||"",align=align||"",padding=(padding||"").slice(-1)||" ",width=width||"",precision=precision||"";val=vals[+flags?flags-1:index];index++;if(type.match(/[duobxXf]{1}/)){val=Number(val)}else{val=String(val)}switch(type){case"d":case"u":return val.dec(align+width,padding);case"o":return val.oct(align+width,padding);case"b":return val.bin(align+width,padding);case"x":return val.hexl(align+width,padding);case"X":return val.hex(align+width,padding);case"s":return val.pad(align+width,padding);case"c":return String.fromCharCode(val).pad(align+width,padding);case"f":if(precision){val=val.toFixed(precision)}else{if(width){val=val.toExponential(width)}else{val=val.toExponential()}}align=align=="-"?"+":"-";return val.toString().pad(align+width,padding)}})}});if(!String.prototype.trim){extend(String.prototype,"trim",function trim(){return this.trimRight().trimLeft()})}if(!String.prototype.trimRight){extend(String.prototype,"trimRight",function trimRight(){return this.remove(/^\s\s*/)})}if(!String.prototype.trimLeft){extend(String.prototype,"trimLeft",function trimLeft(){return this.remove(/\s\s*$/)})}})();
+(function (){var domDefineProperty=false,objectIdStore=[],objectDescriptorStore=[];try{Object.defineProperty({},"x",{})}catch(e){domDefineProperty=true}if(typeof window!=="undefined"&&window.__jstExtend__){var extend=window.__jstExtend__}else{var extend=function (prototype,methods){var title=null;switch(prototype){case Array:title="Array.";break;case Array.prototype:title="Array#";break;case Function:title="Function.";break;case Function.prototype:title="Function#";break;case Number:title="Number.";break;case Number.prototype:title="Number#";break;case Object:title="Object.";break;case Object.prototype:title="Object#";break;case String:title="String.";break;case String.prototype:title="String#";break;case Math:title="Math.";break;case Date:title="Date.";break;case Date.prototype:title="Date#";break;default:throw new Error("Override detector found an unknown prototype being extended.")}if(typeof methods==="string"){var n=methods,methods={};methods[n]=arguments[2]}for(name in methods){var method=methods[name];if(domDefineProperty){var id=-1;for(var i=0;i<objectIdStore.length;i++){if(objectIdStore[i]===prototype){id=i}}id=id<0?objectIdStore.push(prototype)-1:id;if(!objectDescriptorStore[id]){objectDescriptorStore[id]={}}objectDescriptorStore[id][name]={writable:true,enumerable:false,configurable:true};prototype[name]=method}else{Object.defineProperty(prototype,name,{value:method,writable:true,enumerable:false,configurable:true})}}}}if(typeof module!=="undefined"&&module.exports){module.exports.repl=function (){var vm=require("vm"),repl=require("repl");process.stdin.removeAllListeners("keypress");var ctx=repl.start("toolkit> ").context;ctx.Array=Array;ctx.Object=Object;ctx.Number=Number;ctx.Date=Date;ctx.RegExp=RegExp;ctx.String=String;ctx.Function=Function}}extend(Array,{intersect:function intersect(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}return arrays.first().filter(function (val){return arrays.every(function (arg){return arg.contains(val)})})},diff:function diff(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}var vals=arrays.flatten(1);return vals.filter(function (a){return vals.indexOf(a)==vals.lastIndexOf(a)})},union:function union(arrays){if(arguments.length>1){arrays=Array.prototype.slice.call(arguments)}else{if(arguments.length===0||arrays.length===0){return[]}}return Array.prototype.concat.apply([],arrays).unique()},range:function range(start,stop,step){if(arguments.length===1){stop=start;step=start=(stop<0?-1:1)}else{if(arguments.length===0){return[]}else{if(step===undefined){step=(stop<start?-1:1)}else{if(step===0||isNaN(step)){throw new RangeError("Step must be an valid integer and not be equal to 0.")}}}}step=Number(step),stop=Number(stop),start=Number(start);var arr=[];if(stop<start){if(step>=0){throw new RangeError("Stop must not be greater than start if step is to be positive.")}for(var i=start,arr=[];i>=stop;arr.push(i),i+=step){}}if(stop>start){if(step<=0){throw new RangeError("Stop must not be less than start if step is to be negative.")}for(var i=start,arr=[];i<=stop;arr.push(i),i+=step){}}return arr}});extend(Array.prototype,{concat$:function concat$(){var args=Array.prototype.slice.call(arguments).flatten(1);this.splice.apply(this,[this.length,0].concat(args));return this},swap:function swap(index1,index2){return this.clone().swap$(index1,index2)},swap$:function swap$(index1,index2){if(!Object.hasOwnProperty.call(this,Number(index1))){throw new RangeError("Array#swap: index1 does not exist within the array.")}if(!Object.hasOwnProperty.call(this,Number(index2))){throw new RangeError("Array#swap: index2 does not exist within the array.")}var value=this[index1];this[index1]=this[index2];this[index2]=value;return this},contains:function contains(values){if(arguments.length===0){return false}args=Array.prototype.slice.call(arguments);return args.every(function (arg){return !!~this.indexOf(arg)}.bind(this))},remove$:function remove$(){if(arguments.length===0){return this}exclude=Array.prototype.slice.call(arguments);return this.filter$(function (val){return !exclude.contains(val)})},remove:function remove(){if(arguments.length===0){return this.clone()}exclude=Array.prototype.slice.call(arguments);return this.filter(function (val){return !exclude.contains(val)})},shuffle:function shuffle(){var arr=this.clone();for(var index=0;index<arr.length-1;index++){arr.swap$(index,Number.random(index,arr.length-1).round())}return arr},shuffle$:function shuffle$(){for(var index=0;index<this.length-1;index++){this.swap$(index,Number.random(index,this.length-1).round())}return this},clone:function clone(){return this.slice()},intersect:function intersect(){return Array.intersect(Array.prototype.slice.call(arguments).concat([this]))},diff:function diff(){return Array.diff(Array.prototype.slice.call(arguments).concat([this]))},union:function union(){return Array.union(Array.prototype.slice.call(arguments).concat([this]))},chunk:function chunk(size){for(var arr=[];this.length>0;arr.push(this.splice(0,size))){}return arr},chunk$:function chunk$(size){for(var i=0,length=this.length/size;i<length;i++){this.splice(i,0,this.splice(i,size))}return this},unique:function unique(){return this.filter(function (a,idx){return this.indexOf(a)==idx}.bind(this))},each:function each(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=[],result;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&(result=callback.call(thisArg,self[i],i,self))!==undefined){return result}}},flatten:function flatten(level){if(level===undefined){level=-1}else{if(level==0){return this.clone()}}return this.reduce(function (a,b){return a.concat((Array.isArray(b)&&level!=0)?b.flatten(level-1):[b])},[])},flatten$:function flatten$(level){if(level===undefined){level=-1}for(var i=0,length=this.length;i<length;i++){if(Array.isArray(this[i])&&level!=0){this.splice.apply(this,[i,1].concat(this[i].flatten(level-1)))}}return this},sum:function sum(){return this.reduce(function (a,b){return Number(a)+Number(b)})},product:function product(){return this.reduce(function (a,b){return Number(a)*Number(b)})},first:function first(num){return num?this.slice(0,num||1):this[0]},last:function last(num){return num?this.slice(this.length-(num||1)):this[this.length-1]},clean:function clean(){return this.filter(function (val){return !!val})},clean$:function clean$(){return this.filter$(function (val){return !!val})},filter$:function filter$(callback,scope){for(var i=0;i<this.length;i++){if(!callback.call(scope,this[i],i,this)){this.splice(i,1)&&i--}}return this},map$:function map$(callback,scope){for(var i=0;i<this.length;i++){this[i]=callback.call(scope,this[i],i,this)}return this},invoke:function invoke(callback){return this.map(function (val){return val[callback].apply(val,Array.prototype.slice.call(this,1))},arguments)},invoke$:function invoke$(callback){return this.map$(function (val){return val[callback].apply(val,Array.prototype.slice.call(this,1))},arguments)},pluck:function pluck(prop){return this.map(function (val){if(Array.isArray(prop)){return Object.filter(val,prop)}return val[prop]})},pluck$:function pluck$(prop){return this.map$(function (val){if(Array.isArray(prop)){return Object.filter(val,prop)}return val[prop]})},grep:function grep(regex){return this.filter(function (val){return !!val.match(regex)})},grep$:function grep$(regex){return this.filter$(function (val){return !!val.match(regex)})},sort$:function sort$(sort){var sorted=(typeof sort==="function")?this.sort(sort):this.sort();sorted.forEach(function (val,i){this[i]=val},this);return this},sortBy:function sortBy(cmp,sort){if(cmp===undefined){return(typeof sort==="function")?this.sort(sort):this.sort()}if(sort===undefined){sort=function (a,b){return String(a)-String(b)}}var arr=this[typeof cmp==="function"?"map":"pluck"](cmp).map(function (val,i){return{key:i,val:val}});return arr.sort(function (a,b){return sort(a.val,b.val)}).map(function (val){return this[val.key]},this)},sortBy$:function sortBy$(cmp,sort){this.sortBy(cmp,sort).forEach(function (v,i){this[i]=v},this);return this},fetch:function fetch(order){if(typeof order=="function"){order=this.map(order)}if(!Array.isArray(order)){order=Array.prototype.slice.call(arguments)}var arr=[];order.forEach(function (o,i){arr[o]=this[i]},this);return arr}});if(!Array.isArray){extend(Array,"isArray",function isArray(arr){return Object.prototype.toString.call(arr)==="[object Array]"})}if(!Array.prototype.forEach){extend(Array.prototype,"forEach",function forEach(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if(i in self){callback.call(thisArg,self[i],i,self)}}})}if(!Array.prototype.map){extend(Array.prototype,"map",function map(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=new Array(length);if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if(i in self){arr[i]=callback.call(thisArg,self[i],i,self)}}return arr})}if(!Array.prototype.filter){extend(Array.prototype,"filter",function filter(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0,arr=[];if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&callback.call(thisArg,self[i],i,self)){arr.push(self[i])}}return arr})}if(!Array.prototype.every){extend(Array.prototype,"every",function every(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&!callback.call(thisArg,self[i],i,self)){return false}}return true})}if(!Array.prototype.some){extend(Array.prototype,"some",function some(callback){var self=Object(this),thisArg=arguments[1],length=this.length>>>0;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}for(var i=0;i<length;i++){if((i in self)&&callback.call(thisArg,self[i],i,self)){return true}}return false})}if(!Array.prototype.reduce){extend(Array.prototype,"reduce",function reduce(callback){var self=Object(this),value=arguments[1],length=this.length>>>0,i=0,j=i;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}if(arguments.length<=1){if(!length){throw new TypeError("Reduce of empty array with no initial value.")}for(i=-1;j<self.length;j++){if(Object.hasOwnProperty.call(self,String(j))){i=j;break}}if(i===-1){throw new TypeError("Reduce of empty array with no initial value.")}value=self[i++]}for(;i<length;i++){if(Object.hasOwnProperty.call(self,i)){value=callback.call(undefined,value,self[i],i,self)}}return value})}if(!Array.prototype.reduceRight){extend(Array.prototype,"reduceRight",function reduceRight(callback){var self=Object(this),value=arguments[1],length=this.length>>>0,i=length-1,j=i;if(!Function.isFunction(callback)){throw new TypeError(callback+" is not a function.")}if(arguments.length<=1){if(!length){throw new TypeError("Array length is 0 and no initial value given.")}for(i=-1;j>=0;j--){if(Object.hasOwnProperty.call(self,String(j))){i=j;break}}if(i===-1){throw new TypeError("Reduce of empty array with no initial value.")}value=self[i--]}for(;i>=0;i--){if(Object.hasOwnProperty.call(self,i)){value=callback.call(undefined,value,self[i],i,self)}}return value})}if(!Array.prototype.indexOf){extend(Array.prototype,"indexOf",function indexOf(value){var self=Object(this),length=this.length>>>0,index=(arguments.length<=1)?0:Number(arguments[1]);index=index<0?length-Math.abs(index):index;for(var i=index;i<length;i++){if((i in self)&&self[i]===value){return i}}return -1})}if(!Array.prototype.lastIndexOf){extend(Array.prototype,"lastIndexOf",function lastIndexOf(value){if(this===void 0||this===null){throw new TypeError()}var self=Object(this),length=this.length>>>0,index=length;if(length===0){return -1}if(arguments.length>1){index=Number(arguments[1]);if(index!==index){index=0}else{if(index!==0&&index!==(1/0)&&index!==-(1/0)){index=(index>0||-1)*Math.floor(Math.abs(index))}}}var i=(index>=0)?Math.min(index,length-1):length-Math.abs(index);for(;i>=0;i--){if((i in self)&&(self[i]===value)){return i}}return -1})}extend(Date.prototype,{fuzzyDiff:function fuzzyDiff(date,suffix,prefix){if(!(date instanceof Date)){date=new Date(date)}var delta=this.getTime()-date.getTime();var units={second:1000,minute:60000,hour:3600000,day:86400000,year:31557600000};var keys=Object.keys(units),divs=Object.values(units);for(var i=0;i<divs.length;i++){if((delta/divs[i])<1){var time=(delta/divs[i-1]),key=keys[i-1];if(time>1){key+="s"}if(arguments.length<3){prefix=(time.round()==time)?"exactly":"about"}if(arguments.length<2){suffix="ago"}return"%s %d %s %s".sprintf(prefix,time.round(),key,suffix)}}}});if(!Date.now){extend(Date,"now",function now(){return(new Date()).getTime()})}extend(Date,{SECOND:1,MINUTE:60,HOUR:3600,DAY:86400,YEAR:31557600,DECADE:315576000});if(isNaN(Date.parse("2011-06-15T21:40:05+06:00"))){Date=(function (NativeDate){var Date=function (Y,M,D,h,m,s,ms){var length=arguments.length;if(this instanceof NativeDate){var date=length==1&&String(Y)===Y?new NativeDate(Date.parse(Y)):length>=7?new NativeDate(Y,M,D,h,m,s,ms):length>=6?new NativeDate(Y,M,D,h,m,s):length>=5?new NativeDate(Y,M,D,h,m):length>=4?new NativeDate(Y,M,D,h):length>=3?new NativeDate(Y,M,D):length>=2?new NativeDate(Y,M):length>=1?new NativeDate(Y):new NativeDate();date.constructor=Date;return date}return NativeDate.apply(this,arguments)};var isoDateExpression=new RegExp("^(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:Z|(?:([-+])(\\d{2}):(\\d{2})))?)?)?)?$");for(var key in NativeDate){Date[key]=NativeDate[key]}Date.now=NativeDate.now;Date.UTC=NativeDate.UTC;Date.prototype=NativeDate.prototype;Date.prototype.constructor=Date;Date.parse=function parse(string){var match=isoDateExpression.exec(string);if(match){match.shift();for(var i=1;i<7;i++){match[i]=+(match[i]||(i<3?1:0));if(i==1){match[i]--}}var minutesOffset=+match.pop(),hourOffset=+match.pop(),sign=match.pop();var offset=0;if(sign){if(hourOffset>23||minuteOffset>59){return NaN}offset=(hourOffset*60+minuteOffset)*60000*(sign=="+"?-1:1)}return NativeDate.UTC.apply(this,match)+offset}return NativeDate.parse.apply(this,arguments)};return Date})(Date)}extend(Function,{isFunction:function compose(func){return(typeof func==="function")&&func.call},compose:function compose(funcs){if(!Array.isArray(funcs)){funcs=Array.prototype.slice.call(arguments)}funcs=funcs.reverse();return function (arg){return funcs.reduce(function (a,b){return b(a)},arg)}}});extend(Function.prototype,{cache:function cache(time,ident){time=isNaN(time)?-1:time;ident=ident||function (id){return(typeof id=="object")?Object.id(id):id.toString()};var cache={},callback=this,timeouts={};return function (){var args=Array.prototype.slice.call(arguments),id="("+args.map(ident).join(",")+")";if(!(id in cache)){cache[id]=callback.apply(callback,args)}else{if(id in timeouts){clearTimeout(timeouts[id]);delete timeouts[id]}}if(time>0){timeouts[id]=setTimeout(function (){delete cache[id]},time)}return cache[id]}},delay:function delay(callback,time,scope){return setTimeout(function (args){callback.apply(scope,[this()].concat(Array.prototype.slice.call(args,2)))}.bind(this,arguments),time)},once:function once(scope){var called=false,val=null;return function (args){if(!called){called=true;val=this.apply(scope,args)}return val}.bind(this,Array.prototype.slice.call(arguments))}});if(!Function.prototype.bind){extend(Function.prototype,"bind",function bind(thisArg){if(!Function.isFunction(this)){throw new TypeError(this+" is not a function.")}var args=Array.prototype.slice.call(arguments,1),self=this,target=function (){};function bound(){return self.apply(this instanceof target?this:thisArg,args.concat(Array.prototype.slice.call(arguments)))}target.prototype=this.prototype;bound.prototype=new target();return bound})}extend(Number,{random:function random(start,end){return(start=start||0)+(((end||start+1)-start)*Math.random())}});extend(Number.prototype,{chr:function (){return String.fromCharCode(this)},odd:function (){return !this.even()},even:function (){return(this%2)==0},gcd:function gcd(){return Array.prototype.slice.call(arguments).reduce(function (a,b){if(a==0||b==0){return a|b}for(var shift=0;((a|b)&1)==0;shift++){a>>=1;b>>=1}while((a&1)==0){a>>=1}do{while((b&1)==0){b>>=1}if(a<b){b-=a}else{var diff=a-b;a=b;b=diff}b>>=1}while(b!=0);return a<<shift},this)},lcm:function lcm(){var nums=Array.prototype.slice.call(arguments),gcd=this.gcd.apply(this,nums);return Math.abs(nums.product()*this)/gcd},ceil:function ceil(){return Math.ceil(this)},floor:function floor(){return Math.floor(this)},abs:function abs(){return Math.abs(this)},round:function round(digits){digits=digits||0;if(digits==0){return Math.round(this)}else{if(digits<0){return Number(this.toPrecision(this.floor().toString().length-digits.abs()))}else{return Number(this.toFixed(digits))}}},radix:function radix(base,size,character){return this.toString(base).pad(-size,(character||"0"))},bin:function bin(size,character){return this.radix(2,size,character)},oct:function oct(size,character){return this.radix(8,size,character)},dec:function dec(size,character){return this.radix(10,size,character)},hexl:function hexl(size,character){return this.radix(16,size,character)},hex:function hex(size,character){return this.radix(16,size,character).toUpperCase()},abbr:function abbr(digits,binary){binary=!!(binary==undefined?false:binary);var prefixes={k:binary?1<<10:1000,M:binary?1<<20:1000000,G:binary?1<<30:1000000000,T:binary?Math.pow(2,40):1000000000000,P:binary?Math.pow(2,50):1000000000000000,E:binary?Math.pow(2,60):1000000000000000000,Z:binary?Math.pow(2,70):1e+21,Y:binary?Math.pow(2,80):1e+24};var keys=Object.keys(prefixes),divs=Object.values(prefixes);if(divs[0]>this){return this.toFixed(digits)}for(var i=0;i<divs.length;i++){if((this/divs[i])<1){return(this/divs[i-1]).toFixed(digits)+keys[i-1]}}return(this/divs.last()).toFixed(digits)+keys.last()}});extend(Object,{value:function set(obj,key){var desc=Object.getOwnPropertyDescriptor(obj,key);if(desc&&!Object.getOwnPropertyDescriptor(obj,key).writable){return obj[key]}return(arguments.length===2)?obj[key]:(obj[key]=arguments[2])},remove:function remove(obj,key){if(!Object.getOwnPropertyDescriptor(obj,key).configurable){return false}if(obj.__ownPropertyDescriptors__){delete obj.__ownPropertyDescriptors__[key]}return delete obj[key]},id:function id(obj){if(!objectIdStore.contains(obj)){objectIdStore.push(obj)}return objectIdStore.indexOf(obj)},alias:function alias(object,property,alias,complete){var desc=Object.getOwnPropertyDescriptor(object,property);if(!complete){Object.defineProperty(object,alias,desc)}else{if(("get" in desc)||("value" in desc)){delete desc.value,delete desc.writable;desc.get=function (){return object[property]}}desc.set=function (val){return object[property]=val};Object.defineProperty(object,alias,desc)}return object},values:function values(obj){var arr=[];Object.keys(obj).forEach(function (key){arr.push(obj[key])});return arr},forEach:function forEach(obj,callback,scope){return Object.keys(obj).forEach(function (key){return callback.call(scope,key,obj[key],obj)})},isObject:function isObject(){return Array.prototype.slice.call(arguments).every(function (value){return Object(value)===value})},each:function each(obj,callback,scope){var key,result;for(key in obj){if(key!=="__proto__"){if((result=callback.call(scope,key,obj[key],this))!==undefined){return result}}}},map:function map(object,callback,scope){var obj=Object.clone(object);Object.map$(obj,callback,scope);return obj},map$:function map$(obj,callback,scope){Object.forEach(obj,function (key,val){Object.value(obj,key,callback.call(scope,key,val))});return obj},getOwnPropertyDescriptors:function getOwnPropertyDescriptors(object){var descriptors={};Object.getOwnPropertyNames(object).forEach(function (key){descriptors[key]=Object.getOwnPropertyDescriptor(object,key)});return descriptors},reduce:function reduce(obj,callback,start,scope){Object.forEach(obj,function (key,val){start=callback.call(scope,start,key,obj[key])});return start},merge:function merge(objects,level){if(Object.isObject(objects,level)){objects=Array.prototype.slice.call(arguments),level=0}level=(level===undefined)?0:level;return objects.reduce(function (group,obj){Object.forEach(obj,function (key,val){if(!val in group||level==0||!Object.isObject(group[key])||!Object.isObject(val)){group[key]=val}else{group[key]=Object.merge([group[key],val],level-1)}});return group},{})},merge$:function merge$(object,objects,level){if(Array.isArray(objects)){objects=[object].concat(objects)}else{objects=Array.prototype.slice.call(arguments);level=undefined}var obj=Object.merge.apply(undefined,objects,level);Object.filter$(object,function (key,val){return Object.hasOwnProperty.call(obj,key)});Object.map$(object,function (key,val){return obj[key]});Object.keys(obj).diff(Object.keys(object)).forEach(function (key){Object.value(object,key,obj[key])});return object},clone:function clone(obj,inherit){inherit=(inherit===undefined)?true:false;var obj=Object.create(Object.getPrototypeOf(obj),inherit?Object.getOwnPropertyDescriptors(obj):undefined);return obj},filter:function filter(object,callback,scope){return Object.filter$(Object.clone(object),callback,scope)},filter$:function filter$(obj,callback,scope){if(Array.isArray(callback)){var keys=callback.invoke("toString")}Object.forEach(obj,function (key,val){if(Array.isArray(callback)){if(!keys.contains(key)){Object.remove(obj,key)}}else{if(callback.call(scope,key,val,obj)===false){Object.remove(obj,key)}}});return obj},clean:function clean(obj){return Object.filter(obj,function (key,val){return !!val})},clean$:function clean$(obj){return Object.filter$(obj,function (key,val){return !!val})},size:function size(obj){return Object.keys(obj).length},combine:function combine(keys,values){var obj={};keys.forEach(function (key,i){obj[key]=values[i]});return obj},hash:function hash(object){return Object.hash$(Object.clone(object))},hash$:function hash$(object){return Object.defineProperties(object,{size:{value:function (){return Object.size(this)},writable:true,enumerable:false,configurable:true},keys:{value:function keys(callback,scope){return Object.keys(this)},writable:true,enumerable:false,configurable:true},each:{value:function each(callback,scope){return Object.each(this,callback,scope)},writable:true,enumerable:false,configurable:true},forEach:{value:function forEach(callback,scope){return Object.forEach(this,callback,scope)},writable:true,enumerable:false,configurable:true},map:{value:function map(callback,scope){return Object.map(this,callback,scope)},writable:true,enumerable:false,configurable:true},map$:{value:function map$(callback,scope){return Object.map$(this,callback,scope)},writable:true,enumerable:false,configurable:true},reduce:{value:function reduce(callback,start){return Object.reduce(this,callback,start)},writable:true,enumerable:false,configurable:true},filter:{value:function filter(callback,scope){return Object.filter(this,callback,scope)},writable:true,enumerable:false,configurable:true},filter$:{value:function filter$(callback,scope){return Object.filter$(this,callback,scope)},writable:true,enumerable:false,configurable:true},clean:{value:function clean(callback,scope){return Object.clean(this,callback,scope)},writable:true,enumerable:false,configurable:true},clean$:{value:function clean$(callback,scope){return Object.clean$(this,callback,scope)},writable:true,enumerable:false,configurable:true},clone:{value:function clone(callback,scope){return Object.clone(this,callback,scope)},writable:true,enumerable:false,configurable:true},merge:{value:function merge(){return Object.merge.apply(undefined,[this].concat(Array.prototype.slice.call(arguments)))},writable:true,enumerable:false,configurable:true},merge$:{value:function merge$(){return Object.merge$.apply(undefined,[this].concat(Array.prototype.slice.call(arguments)))},writable:true,enumerable:false,configurable:true}})}});if(!Object.getPrototypeOf){extend(Object,"getPrototypeOf",function getPrototypeOf(object){return object.__proto__||object.constructor.prototype||protoStore[Object.id(object)]})}if(!Object.getOwnPropertyDescriptor||domDefineProperty){var oldGetOwnPropertyDescriptor=Object.getOwnPropertyDescriptor,objectDescriptorStore={};extend(Object,"getOwnPropertyDescriptor",function getOwnPropertyDescriptor(object,property){if(object.nodeType&&oldGetOwnPropertyDescriptor){return oldGetOwnPropertyDescriptor(object,property)}if(!Object.isObject(object)){throw new TypeError(object+" is not an object.")}if(!Object.prototype.hasOwnProperty.call(object,property)){return}var descriptor={enumerable:true,writable:true,configurable:true},getter,setter,id=Object.id(object);if((object===Number&&["NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","MAX_VALUE","MIN_VALUE"].contains(property))||(object===Math&&["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2"].contains(property))||(object instanceof Function&&["arguments","length","name","prototype","caller"].contains(property))){descriptor={configurable:false,writable:false,enumerable:false}}if((object===Math&&["cos","pow","log","tan","sqrt","ceil","asin","abs","max","exp","atan2","random","round","floor","acos","atan","min","sin"].contains(property))||(object===String&&property==="fromCharCode")){descriptor={configurable:true,writable:true,enumerable:false}}if(object instanceof RegExp&&["lastIndex","multiline","global","source","ignoreCase"].contains(property)){descriptor={configurable:false,writable:(property=="lastIndex"),enumerable:false}}if((Array.isArray(object)||String.isString(object))&&property==="length"){descriptor={configurable:false,writable:true,enumerable:false}}else{if(objectDescriptorStore[id]&&(property in objectDescriptorStore[id])){descriptor=objectDescriptorStore[id][property]}}if(descriptor.writable===false){if(Object.prototype.__lookupGetter__&&(getter=object.__lookupGetter__(property))){descriptor.writable=false;descriptor.get=getter}if(Object.prototype.__lookupSetter__&&(setter=object.__lookupSetter__(property))){descriptor.writable=false;descriptor.set=setter}}if(!("set" in descriptor||"get" in descriptor)){descriptor.value=object[property]}return descriptor})}if(!Object.getOwnPropertyNames){extend(Object,"getOwnPropertyNames",function getOwnPropertyNames(object){var names=[];if(object===Number){names=["NaN","NEGATIVE_INFINITY","POSITIVE_INFINITY","MAX_VALUE","MIN_VALUE"]}else{if(object===Math){names=["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2","cos","pow","log","tan","sqrt","ceil","asin","abs","max","exp","atan2","random","round","floor","acos","atan","min","sin"]}else{if(object===String){names=["fromCharCode"]}}}if(object instanceof RegExp){names.push.apply(names,["lastIndex","multiline","global","source","ignoreCase"])}else{if(object instanceof Function){names.push.apply(names,["arguments","length","name","prototype","caller"])}else{if(Array.isArray(object)||String.isString(object)){names.push("length")}else{if(Object.prototype.hasOwnProperty.call(object,"constructor")){names.push("constructor")}}}}return names.concat(Object.keys(objectDescriptorStore[Object.id(object)]||{})).concat(Object.keys(object)).unique()})}if(!Object.create){var protoStore=[];extend(Object,"create",function create(prototype,descriptors){if(prototype!==null&&Object(prototype)!==prototype){throw new TypeError("Object prototype may only be an Object or null")}var object={};if(prototype!==null){var type=function (){};type.prototype=prototype;object=new type()}if(descriptors!==undefined){Object.defineProperties(object,descriptors)}if(object.__proto__!==undefined){object.__proto__=prototype}else{protoStore[Object.id(object)]=prototype}return object})}if(!Object.defineProperty||domDefineProperty){var oldDefineProperty=Object.defineProperty,definePropertyError=function (object,name,descriptor){if(!Object.isObject(descriptor)){return"Property description must be an object: "+descriptor}if(!Object.isObject(object)){return"Object.defineProperty called on non-object"}if("get" in descriptor){if(!object.__defineGetter__){return"Getters are not supported on this javascript engine."}if(!Function.isFunction(descriptor.get)){return"Getter must be a function: "+descriptor.get}}if("set" in descriptor){if(!object.__defineSetter__){return"Setters are not supported on this javascript engine."}if(!Function.isFunction(descriptor.set)){return"Setter must be a function: "+descriptor.get}}if(("get" in descriptor||"set" in descriptor)&&("value" in descriptor||descriptor.writable)){return"A property cannot both have accessors and be writable or have a value: "+object}};extend(Object,"defineProperty",function defineProperty(object,name,descriptor){if(object.nodeType&&oldDefineProperty){oldDefineProperty(object,name,descriptor)}var id=Object.id(object),error,prototype;if((error=definePropertyError(object,name,descriptor))){throw new TypeError(error)}if(object.__defineGetter__){if((name in object)&&(object.__lookupGetter__(name))){prototype=object.__proto__;object.__proto__=Object.prototype;delete object[name]}if("get" in descriptor){object.__defineGetter__(name,descriptor.get)}if("set" in descriptor){object.__defineSetter__(name,descriptor.set)}}if(!objectDescriptorStore[id]){objectDescriptorStore[id]={}}if(!descriptor.writable){descriptor.writable=false}if(!descriptor.configurable){descriptor.configurable=false}if(!descriptor.enumerable){descriptor.enumerable=false}if(!("get" in descriptor||"set" in descriptor)){object[name]=descriptor.value}objectDescriptorStore[id][name]=descriptor;if(prototype){object.__proto__=prototype}return object})}if(!Object.defineProperties||domDefineProperty){extend(Object,"defineProperties",function defineProperties(object,descriptors){if(!Object.isObject(object)){throw new TypeError("Object.defineProperties called on non-object")}var name,error;for(name in descriptors){if(error=definePropertyError(object,name,descriptors[name])){throw new TypeError(error)}}for(name in descriptors){Object.defineProperty(object,name,descriptors[name])}return object})}if(!Object.seal){var sealedStore=[]}extend(Object,"seal",function seal(object){if(!Object.isObject(object)){throw new TypeError("Object.seal called on non-object")}sealedStore[Object.id(object)]=true;return object});if(!Object.isSealed){extend(Object,"isSealed",function isSealed(object){if(!Object.isObject(object)){throw new TypeError("Object.isSealed called on non-object")}return !!sealedStore[Object.id(object)]})}if(!Object.freeze){var frozenStore=[]}extend(Object,"freeze",function freeze(object){if(!Object.isObject(object)){throw new TypeError("Object.freeze called on non-object")}frozenStore[Object.id(object)]=true;return object});if(!Object.isFrozen){extend(Object,"isFrozen",function isFrozen(object){if(!Object.isObject(object)){throw new TypeError("Object.isFrozen called on non-object")}return !!frozenStore[Object.id(object)]})}if(!Object.preventExtensions){var preventExtensionsStore=[]}extend(Object,"preventExtensions",function preventExtensions(object){if(!Object.isObject(object)){throw new TypeError("Object.preventExtensions called on non-object")}preventExtensionsStore[Object.id(object)]=true;return object});if(!Object.isExtensible){extend(Object,"isExtensible",function isExtensible(object){if(!Object.isObject(object)){throw new TypeError("Object.isExtensible called on non-object")}var id=Object.id(object);return !preventExtensionsStore[id]&&!sealedStore[id]})}if(!Object.keys){extend(Object,"keys",function keys(object){if(object!==Object(object)){throw new TypeError("Object.keys called on non-object")}var keys=[],key;for(key in object){if(object.hasOwnProperty(key)){keys.push(key)}}keys=keys.filter(function (key){return Object.prototype.propertyIsEnumerable.call(object,key)});if(String.isString(object)&&!(0 in (new String(" ")))){keys=keys.concat(Array.range(0,object.length-1))}return keys.map(String)})}if(domDefineProperty){var oldPropertyIsEnumerable=Object.prototype.propertyIsEnumerable;Object.prototype.propertyIsEnumerable=function propertyIsEnumerable(key){var desc=objectDescriptorStore[Object.id(this)];if(desc&&desc[key]){return desc[key].enumerable===true}else{if(oldPropertyIsEnumerable){oldPropertyIsEnumerable.call(this,key)}else{for(var name in this){if(name==key){return true}}}}return true}}extend(String,{isString:function isString(object){return typeof object==="string"||object instanceof String},UUID:function UUID(){return Array.range(0,35).map(function (i){switch(i){case 8:case 13:case 23:return"-";case 14:i=4;break;case 19:i=(Number.random(0,16).floor()&3)|8;break;default:i=Number.random(0,16).floor();break}return"0123456789ABCDEF".charAt(i)}).join("")}});extend(String.prototype,{repeat:function repeat(num){var str="";for(var i=0,str="";i<(num||1);i++){str+=this}return str},chars:function chars(){for(var i=0,arr=[];i<this.length;i++){arr.push(this.charAt(i))}return arr},count:function count(substr,mod){return this.match(RegExp(substr,mod||"gi")).length},insert:function insert(substr,pos){return this.substr(0,pos||0)+substr+this.substr(pos||0)},remove:function remove(substr){return this.replace(substr,"")},reverse:function reverse(){return this.chars().reverse().join("")},ucfirst:function ucfirst(){return this.charAt(0).toUpperCase()+this.substr(1)},swapcase:function swapcase(){return this.chars().map(function (a){return/[a-z]/.test(a)?a.toUpperCase():a.toLowerCase()}).join("")},rpad:function rpad(len,chars){len=Number(len);if(len<this.length){return this.valueOf()}for(var str=this;str.length<len;str+=(chars||" ")){}return str.substr(0,len)},lpad:function lpad(len,chars){len=Number(len);if(len<this.length){return this.valueOf()}chars=(chars||" ").reverse();for(var str=this;str.length<len;str=(chars+str)){}return str.substr(str.length-len)},pad:function pad(len,chars){return this[len>0?"rpad":"lpad"](Math.abs(len),chars)},soundex:function soundex(){return this.substr(0,1).toUpperCase()+this.toUpperCase().substr(1).remove(/[^A-Z]/gi).trim().replace(/DG/g,"G").replace(/GH/g,"H").replace(/GN|KN/g,"N").replace(/PH/g,"F").replace(/MP([STZ])/g,"M$1").replace(/^PS/g,"S").replace(/^PF/g,"F").replace(/MB/g,"M").replace(/TCH/g,"CH").replace(/[AEIOUHWY]/g,"0").replace(/[BFPV]/g,"1").replace(/[CGJKQSXZ]/g,"2").replace(/[DT]/g,"3").replace(/[L]/g,"4").replace(/[MN]/g,"5").replace(/[R]/g,"6").replace(/(\w)\1+/g,"$1").slice(0,3).rpad(3,"0")},distance:function distance(c){var s,l=(s=this.split("")).length,t=(c=c.split("")).length,i,j,m,n;if(!(l||t)){return Math.max(l,t)}for(var a=[],i=l+1;i;a[--i]=[i]){}for(i=t+1;a[0][--i]=i;){}for(i=-1,m=s.length;++i<m;){for(j=-1,n=c.length;++j<n;){a[(i*=1)+1][(j*=1)+1]=Math.min(a[i][j+1]+1,a[i+1][j]+1,a[i][j]+(s[i]!=c[j]))}}return a[l][t]},soundex:function soundex(){return this.substr(0,1).toUpperCase()+this.toUpperCase().substr(1).remove(/[^A-Z]/gi).trim().replace(/DG/g,"G").replace(/GH/g,"H").replace(/GN|KN/g,"N").replace(/PH/g,"F").replace(/MP([STZ])/g,"M$1").replace(/^PS/g,"S").replace(/^PF/g,"F").replace(/MB/g,"M").replace(/TCH/g,"CH").replace(/[AEIOUHWY]/g,"0").replace(/[BFPV]/g,"1").replace(/[CGJKQSXZ]/g,"2").replace(/[DT]/g,"3").replace(/[L]/g,"4").replace(/[MN]/g,"5").replace(/[R]/g,"6").replace(/(\w)\1+/g,"$1").rpad(3,"0")},chunk:function chunk(len){this.chars().chunk(len).map(function (chars){return chars.join("")})},btoa:function btoa(){if(typeof window!=="undefined"&&window.btoa){return window.btoa(this)}var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",output="",input=this.valueOf();for(i=0;i<input.length;i+=3){var c1=input.charCodeAt(i),c2=input.charCodeAt(i+1),c3=input.charCodeAt(i+2);var e1=c1>>2,e2=((c1&3)<<4)|(c2>>4),e3=((c2&15)<<2)|(c3>>6),e4=c3&63;if(isNaN(c1)){e3=e4=64}else{if(isNaN(c3)){e4=64}}output+=key.charAt(e1)+key.charAt(e2)+key.charAt(e3)+key.charAt(e4)}return output},atob:function atob(){var key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",output="",input=this;return input.split("\n").map(function (line){var output="";for(i=0;i<line.length;i+=4){var e1=key.indexOf(line.charAt(i)),e2=key.indexOf(line.charAt(i+1)),e3=key.indexOf(line.charAt(i+2)),e4=key.indexOf(line.charAt(i+3));var c1=(e1<<2)|(e2>>4),c2=((e2&15)<<4)|(e3>>2),c3=((e3&3)<<6)|e4;output+=String.fromCharCode(c1);if(e3!=64){output+=String.fromCharCode(c2)}if(e4!=64){output+=String.fromCharCode(c3)}}return output}).join("")},sprintf:function sprintf(c){var vals=arguments,regex=/%%|%(?:(\d+)[\$#])?([+-])?('.|0| )?(\d*)(?:\.(\d+))?([bcdfosuxX])/g;var index=0;return this.replace(regex,function (substr,flags,align,padding,width,precision,type){if(substr=="%%"){return"%"}flags=flags||"",align=align||"",padding=(padding||"").slice(-1)||" ",width=width||"",precision=precision||"";val=vals[+flags?flags-1:index];index++;if(type.match(/[duobxXf]{1}/)){val=Number(val)}else{val=String(val)}switch(type){case"d":case"u":return val.dec(align+width,padding);case"o":return val.oct(align+width,padding);case"b":return val.bin(align+width,padding);case"x":return val.hexl(align+width,padding);case"X":return val.hex(align+width,padding);case"s":return val.pad(align+width,padding);case"c":return String.fromCharCode(val).pad(align+width,padding);case"f":if(precision){val=val.toFixed(precision)}else{if(width){val=val.toExponential(width)}else{val=val.toExponential()}}align=align=="-"?"+":"-";return val.toString().pad(align+width,padding)}})}});if(!String.prototype.trim){extend(String.prototype,"trim",function trim(){return this.trimRight().trimLeft()})}if(!String.prototype.trimRight){extend(String.prototype,"trimRight",function trimRight(){return this.remove(/^\s\s*/)})}if(!String.prototype.trimLeft){extend(String.prototype,"trimLeft",function trimLeft(){return this.remove(/\s\s*$/)})}})();
View
2  index.js
@@ -39,7 +39,7 @@ else {
if ( ! objectDescriptorStore[id])
objectDescriptorStore[id] = {};
- objectDescriptorStore[id][name] = (typeof method === 'function') ?
+ objectDescriptorStore[id][name] =
{ writable: (typeof method === 'function'), enumerable: false, configurable: (typeof method === 'function') };
prototype[name] = method;
View
105 lib/array.js
@@ -132,7 +132,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return false;
args = Array.prototype.slice.call(arguments);
- return args.every(function(arg) {
+ return args.every(function (arg) {
return !! ~ this.indexOf(arg);
}.bind(this));
},
@@ -154,7 +154,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return this;
exclude = Array.prototype.slice.call(arguments);
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return ! exclude.contains(val);
});
},
@@ -174,7 +174,7 @@ extend(Array.prototype, {
if (arguments.length === 0) return this.clone();
exclude = Array.prototype.slice.call(arguments);
- return this.filter(function(val) {
+ return this.filter(function (val) {
return ! exclude.contains(val);
});
},
@@ -236,7 +236,7 @@ extend(Array.prototype, {
intersect: function intersect() {
/**
- * Finds values that are contained within all given arrays.
+ * Finds values that are contained within all given arrays. Non-arrays given as parameters will be ignored.
*
* @since 1.0.0
* @alias intersection
@@ -249,13 +249,18 @@ extend(Array.prototype, {
* [[2,3,4],[1,2,3],[3,4,5]].intersect();
* // returns [3]
*
+ * [1,2,3].intersect(2,[3,4]);
+ * // returns [2,3]
+ *
* @returns array
*/
- var arrays = (arguments.length === 0) ?
- this : Array.prototype.slice.call(arguments).concat([this]);
+ var arrays = this.concat.apply(this, Array.prototype.slice.call(arguments));
+
+ if (arrays.length === 0) return [];
+ else if (arrays.length === 1) return arrays[0];
- return arrays.first().filter(function(val) {
- return arrays.every(function(arr) {
+ return arrays.first().filter(function (val) {
+ return arrays.every(function (arr) {
return arr.contains(val);
});
});
@@ -264,7 +269,7 @@ extend(Array.prototype, {
diff: function diff() {
/**
- * Finds all values that are only contained in 1 of the supplied arrays.
+ * Finds all values that are only contained in 1 of the supplied arrays. Non-array values will be conted as single values.
*
* @since 1.0.0
* @alias difference
@@ -279,11 +284,20 @@ extend(Array.prototype, {
* [[1,2,3], [2,3,4], [3,4,5]].diff();
* // returns [1,5]
*
+ * // As of 1.5.3
+ * [1,2,3].diff(2,[3,4]);
+ * // returns [1,4]
+ *
* @returns array
*/
- var arrays = (arguments.length === 0) ? this : Array.prototype.slice.call(arguments);
+ var values = this.concat.apply(this, Array.prototype.slice.call(arguments));
+
+ if (arrays.length === 0) return [];
+ else if (arrays.length === 1) return arrays[0];
+
+ arrays = Array.prototype.concat.apply([], arrays);
- return arrays.flatten(1).filter(function(a,i,t) {
+ return arrays.filter(function (a,i,t) {
return t.indexOf(a) === t.lastIndexOf(a);
});
},
@@ -303,9 +317,12 @@ extend(Array.prototype, {
*
* @returns array
*/
- var arrays = (arguments.length === 0) ? this : Array.prototype.slice.call(arguments);
+ var values = this.concat.apply(this, Array.prototype.slice.call(arguments));
+
+ if (arrays.length === 0) return [];
+ else if (arrays.length === 1) return arrays[0];
- return arrays.flatten(1).unique();
+ return Array.prototype.concat.apply([], arrays).unique();
},
chunk: function chunk(size) {
@@ -356,7 +373,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(a, idx) {
+ return this.filter(function (a, idx) {
return this.indexOf(a) == idx;
}.bind(this));
},
@@ -369,7 +386,7 @@ extend(Array.prototype, {
* @param callback The function to call on each item
* @param thisArg The value to assign to 'this' on the callback
* @example
- * [1,2,3,4,5,6].each(function(val, idx) {
+ * [1,2,3,4,5,6].each(function (val, idx) {
* if (val == 2) return idx;
* });
* // returns 2
@@ -395,12 +412,14 @@ extend(Array.prototype, {
*
* @returns array
*/
- if (level === undefined) level = -1;
- else if (level == 0) return this.clone();
-
- return this.reduce(function(a,b) {
- return a.concat((Array.isArray(b) && level != 0) ? b.flatten(level - 1) : [b]);
- }, []);
+
+ if (arguments.length === 0) level = -1;
+ else if (level === 0) return this.clone();
+
+ for (var i = 0, a = this.clone(); a.some(Array.isArray) && (i != level); i++)
+ a = Array.prototype.concat.apply([], a);
+
+ return a;
},
flatten$: function flatten$(level) {
@@ -417,7 +436,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- if (level === undefined) level = -1;
+ if (arguments.length === 0) level = -1;
for (var i = 0, length = this.length; i < length; i++) {
if (Array.isArray(this[i]) && level != 0)
@@ -438,7 +457,7 @@ extend(Array.prototype, {
*
* @returns int
*/
- return this.reduce(function(a, b) {
+ return this.reduce(function (a, b) {
return Number(a) + Number(b);
});
},
@@ -454,7 +473,7 @@ extend(Array.prototype, {
*
* @returns int
*/
- return this.reduce(function(a, b) {
+ return this.reduce(function (a, b) {
return Number(a) * Number(b);
});
},
@@ -506,7 +525,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(val) {
+ return this.filter(function (val) {
return !! val;
});
},
@@ -524,7 +543,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return !! val;
});
},
@@ -538,7 +557,7 @@ extend(Array.prototype, {
* @param scope The value of this in the callback.
* @example
* var arr = [1,2,3,4,5,6];
- * arr.filter$(function(n) { return n.even() }) === arr; // true
+ * arr.filter$(function (n) { return n.even() }) === arr; // true
* arr;
* // arr = [2,4,6]
*
@@ -560,7 +579,7 @@ extend(Array.prototype, {
* @param scope The value of this in the callback.
* @example
* var arr = [1,2,3];
- * arr.map$(function(n) { return n * n }) === arr;
+ * arr.map$(function (n) { return n * n }) === arr;
* arr;
* // arr == [1,4,9]
*
@@ -585,7 +604,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.map(function(val) {
+ return this.map(function (val) {
return val[callback].apply(val, Array.prototype.slice.call(this, 1));
}, arguments);
},
@@ -605,7 +624,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.map$(function(val) {
+ return this.map$(function (val) {
return val[callback].apply(val, Array.prototype.slice.call(this, 1));
}, arguments);
},
@@ -630,7 +649,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.map(function(val) {
+ return this.map(function (val) {
if (Array.isArray(prop))
return Object.filter(val, prop);
@@ -661,7 +680,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- return this.map$(function(val) {
+ return this.map$(function (val) {
if (Array.isArray(prop))
return Object.filter(val, prop);
@@ -681,7 +700,7 @@ extend(Array.prototype, {
*
* @returns array
*/
- return this.filter(function(val) {
+ return this.filter(function (val) {
return !! val.match(regex);
});
},
@@ -699,7 +718,7 @@ extend(Array.prototype, {
* // arr = ['hello', 'cool']
* @returns self
*/
- return this.filter$(function(val) {
+ return this.filter$(function (val) {
return !! val.match(regex);
});
},
@@ -719,7 +738,7 @@ extend(Array.prototype, {
* @returns self
*/
var sorted = (typeof sort === 'function') ? this.sort(sort) : this.sort();
- sorted.forEach(function(val, i) {
+ sorted.forEach(function (val, i) {
this[i] = val;
}, this);
return this;
@@ -733,7 +752,7 @@ extend(Array.prototype, {
* @param mapping The mapping callback to apply to each value.
* @param [comparison] The comparison callback used in the sort afterwords.
* @example
- * ['hello','world','this','is','nice'].sortBy(function(s) { return s.length; }); // Sort by length
+ * ['hello','world','this','is','nice'].sortBy(function (s) { return s.length; }); // Sort by length
* // returns ['is', 'this', 'nice', 'hello', 'world']
*
* ['hello','world','this','is','nice'].sortBy('length');
@@ -745,16 +764,16 @@ extend(Array.prototype, {
return (typeof sort === 'function') ? this.sort(sort) : this.sort();
if (sort === undefined)
- sort = function(a,b) { return String(a) - String(b) };
+ sort = function (a,b) { return String(a) - String(b) };
// Get the values we intend to sort
- var arr = this[typeof cmp === 'function' ? 'map' : 'pluck'](cmp).map(function(val, i) {
+ var arr = this[typeof cmp === 'function' ? 'map' : 'pluck'](cmp).map(function (val, i) {
return { key: i, val: val };
});
- return arr.sort(function(a,b) {
+ return arr.sort(function (a,b) {
return sort(a.val, b.val);
- }).map(function(val) {
+ }).map(function (val) {
return this[val.key];
}, this);
},
@@ -774,7 +793,7 @@ extend(Array.prototype, {
*
* @returns self
*/
- this.sortBy(cmp, sort).forEach(function(v, i) {
+ this.sortBy(cmp, sort).forEach(function (v, i) {
this[i] = v;
}, this);
@@ -794,7 +813,7 @@ extend(Array.prototype, {
* ['d','b','a','c','e'].fetch(2,1,3);
* // returns ['a','b','c']
*
- * [1,2,3,4,5,6].fetch(function(n,i) { return n % 6; });
+ * [1,2,3,4,5,6].fetch(function (n,i) { return n % 6; });
* // returns [6,1,2,3,4,5]
*
* @returns array
@@ -807,7 +826,7 @@ extend(Array.prototype, {
var arr = [];
- order.forEach(function(o, i) {
+ order.forEach(function (o, i) {
arr[o] = this[i];
}, this);
View
4 lib/date.js
@@ -75,10 +75,10 @@ extend(Date, {
if (isNaN(Date.parse("2011-06-15T21:40:05+06:00"))) {
// XXX global assignment won't work in embeddings that use
// an alternate object for the context.
- Date = (function(NativeDate) {
+ Date = (function (NativeDate) {
// Date.length === 7
- var Date = function(Y, M, D, h, m, s, ms) {
+ var Date = function (Y, M, D, h, m, s, ms) {
var length = arguments.length;
if (this instanceof NativeDate) {
var date = length == 1 && String(Y) === Y ? // isString(Y)
View
22 lib/function.js
@@ -36,8 +36,8 @@ extend(Function, {
funcs = funcs.reverse();
- return function(arg) {
- return funcs.reduce(function(a,b) {
+ return function (arg) {
+ return funcs.reduce(function (a,b) {
return b(a);
}, arg);
}
@@ -55,7 +55,7 @@ extend(Function.prototype, {
* @param time The number of milliseconds before deleting the cache.
* @param ident A callback used to map arguments to ids.
* @example
- * var fibonacci = function(n) {
+ * var fibonacci = function (n) {
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
* };
* // fibonacci(50) will take a several minutes to complete
@@ -66,13 +66,13 @@ extend(Function.prototype, {
* @returns function
*/
time = isNaN(time) ? -1 : time;
- ident = ident || function(id) {
+ ident = ident || function (id) {
return (typeof id == 'object') ? Object.id(id) : id.toString();
}
var cache = {}, callback = this, timeouts = {};
- return function() {
+ return function () {
var args = Array.prototype.slice.call(arguments), id = '(' + args.map(ident).join(',') + ')';
@@ -83,7 +83,7 @@ extend(Function.prototype, {
}
if (time > 0) {
- timeouts[id] = setTimeout(function() {
+ timeouts[id] = setTimeout(function () {
delete cache[id];
}, time);
}
@@ -101,13 +101,13 @@ extend(Function.prototype, {
* @param time The number of milliseconds before calling the function.
* @param scope The value of this within the callback.
* @example
- * Date.now.delay(function(now, then) {
+ * Date.now.delay(function (now, then) {
* log(now - then); // > 50 (Or very near it!)
* }, 50, Date.now());
*
* @returns function
*/
- return setTimeout(function(args) {
+ return setTimeout(function (args) {
callback.apply(scope, [this()].concat(Array.prototype.slice.call(args, 2)));
}.bind(this, arguments), time);
@@ -121,7 +121,7 @@ extend(Function.prototype, {
* @param scope Unfortunately the original function will loose it's scope. Re-add it here.
* @example
* function A() { this.foo = 'bar'; }
- * A.prototype.getFoo = function() { return this.foo; }
+ * A.prototype.getFoo = function () { return this.foo; }
*
* var obj = new A();
* obj.getFoo = obj.getFoo.once(); // INCORRECT! don't forget scope!
@@ -139,7 +139,7 @@ extend(Function.prototype, {
*/
var called = false, val = null;
- return function(args) {
+ return function (args) {
if ( ! called) {
called = true;
@@ -159,7 +159,7 @@ extend(Function.prototype, {
if ( ! Function.prototype.bind)
extend(Function.prototype, 'bind', function bind(thisArg) {
if ( ! Function.isFunction(this)) throw new TypeError(this + ' is not a function.');
- var args = Array.prototype.slice.call(arguments, 1), self = this, target = function() {};
+ var args = Array.prototype.slice.call(arguments, 1), self = this, target = function () {};
function bound() {
return self.apply(this instanceof target ? this : thisArg, args.concat(Array.prototype.slice.call(arguments)));
View
8 lib/number.js
@@ -66,7 +66,7 @@ extend(Number.prototype, {
return (append ? this.round() : '') + ord;
},
- chr: function() {
+ chr: function () {
/**
* Gets the current integer's representing string character.
*
@@ -81,7 +81,7 @@ extend(Number.prototype, {
},
- odd: function() {
+ odd: function () {
/**
* Determine's whether this integer is an odd number. *** Deprecated *** as of 1.6.0 this will be isOdd()
*
@@ -96,7 +96,7 @@ extend(Number.prototype, {
},
- even: function() {
+ even: function () {
/**
* Determine's whether this integer is an even number. *** Deprecated *** as of 1.6.0 this will be isEven()
*
@@ -123,7 +123,7 @@ extend(Number.prototype, {
*
* @returns integer
*/
- return Array.prototype.slice.call(arguments).reduce(function(a, b) {
+ return Array.prototype.slice.call(arguments).reduce(function (a, b) {
if (a == 0 || b == 0)
return a | b;
View
70 lib/object.js
@@ -1,18 +1,22 @@
extend(Object, {
- follow: function follow(obj, keys){
+ follow: function follow(obj, keys, sep){
/**
* Follows a set of keys deep into the recursive object and returns the end value.
*
* @since 1.5.3
* @param obj The object to follow.
* @param keys Either an array of keys or a string of key names seperated by dots.
+ * @param [seperator='.']
* @example
* var obj = {a:{b:{c:'d'}}};
* Object.follow(obj, ['a','b','c'])
* // returns 'd'
*
- * Object.follow(obj, 'a.b') === a.b;
+ * Object.follow(obj, 'a.b') === obj.a.b;
+ * // returns true
+ *
+ * Object.follow(obj, 'a/b', '/') === obj.a.b;
* // returns true
*
* @returns mixed
@@ -21,10 +25,10 @@ extend(Object, {
if (typeof keys !== 'string')
throw new TypeError('Object.follow requires keys to either be an array or string value.');
- keys = keys.split('.');
+ keys = keys.split(sep || '.');
}
- return keys.reduce(function(o,k) {
+ return keys.reduce(function (o,k) {
if (o && (k in o))
return o[k];
}, obj);
@@ -120,12 +124,12 @@ extend(Object, {
if (('get' in desc ) || ('value' in desc)) {
delete desc['value'], delete desc['writable'];
- desc.get = function() {
+ desc.get = function () {
return object[property];
}
}
- desc.set = function(val) {
+ desc.set = function (val) {
return object[property] = val;
}
@@ -149,7 +153,7 @@ extend(Object, {
* @returns array
*/
var arr = [];
- Object.keys(obj).forEach(function(key) {
+ Object.keys(obj).forEach(function (key) {
arr.push(obj[key]);
});
@@ -166,7 +170,7 @@ extend(Object, {
* @param function The callback that takes parameters (key, value, object)
* @param scope The value of this in the callback function.
* @example
- * Object.forEach({1:2,3:4}, function(key, val, obj) {
+ * Object.forEach({1:2,3:4}, function (key, val, obj) {
* log(key + ':' + val)
* });
* // > 1:2
@@ -174,7 +178,7 @@ extend(Object, {
*
* @returns void
*/
- return Object.keys(obj).forEach(function(key) {
+ return Object.keys(obj).forEach(function (key) {
return callback.call(scope, key, obj[key], obj);
});
@@ -190,7 +194,7 @@ extend(Object, {
* Object.isObject({1:2,3:4});
* // returns true
*
- * Object.isObject(function() { });
+ * Object.isObject(function () { });
* // returns true
*
* Object.isObject(123, {});
@@ -198,7 +202,7 @@ extend(Object, {
*
* @returns bool
*/
- return Array.prototype.slice.call(arguments).every(function(value) {
+ return Array.prototype.slice.call(arguments).every(function (value) {
return Object(value) === value;
});
@@ -213,7 +217,7 @@ extend(Object, {
* @param function The callback that takes parameters (key, value, object)
* @param scope The value of this in the callback function.
* @example
- * var ret = Object.each({1:2,3:4}, function(key, val, obj) {
+ * var ret = Object.each({1:2,3:4}, function (key, val, obj) {
* return (key + ':' + val);
* });
* // ret = 1:2
@@ -237,7 +241,7 @@ extend(Object, {
* @param function The callback that takes parameters (value, key) and should return a new value
* @param scope The value of this in the callback function.
* @example
- * Object.map({1:2,3:4}, function(key, val) {
+ * Object.map({1:2,3:4}, function (key, val) {
* return key * val;
* });
* // returns {1:2,3:12}
@@ -262,14 +266,14 @@ extend(Object, {
* @param scope The value of this in the callback function.
* @example
* var obj = {1:2,3:4};
- * Object.map(obj, function(key, val) {
+ * Object.map(obj, function (key, val) {
* return key * val;
* });
* // obj = {1:2,3:12}
*
* @returns self
*/
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
Object.value(obj, key, callback.call(scope, key, val));
});
@@ -303,7 +307,7 @@ extend(Object, {
*/
var descriptors = {};
- Object.getOwnPropertyNames(object).forEach(function(key) {
+ Object.getOwnPropertyNames(object).forEach(function (key) {
descriptors[key] = Object.getOwnPropertyDescriptor(object, key);
});
@@ -320,14 +324,14 @@ extend(Object, {
* @param callback The function to call on each iteration
* @param [start=undefined] The initial value
* @example
- * Object.reduce({1:2,3:4}, function(group, key, val) {
+ * Object.reduce({1:2,3:4}, function (group, key, val) {
* return group + key + val;
* }, 0);
* // returns 10 (0+1+2+3+4)
*
* @returns mixed
*/
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
start = callback.call(scope, start, key, obj[key]);
});
@@ -364,8 +368,8 @@ extend(Object, {
level = (level === undefined) ? 0 : level;
- return objects.reduce(function(group, obj) {
- Object.forEach(obj, function(key, val) {
+ return objects.reduce(function (group, obj) {
+ Object.forEach(obj, function (key, val) {
if ( ! val in group || level == 0 || ! Object.isObject(group[key]) || ! Object.isObject(val)) {
group[key] = val;
}
@@ -410,10 +414,10 @@ extend(Object, {
var obj = Object.merge.apply(undefined, objects, level);
- Object.filter$(object, function(key, val) { return Object.hasOwnProperty.call(obj, key) });
- Object.map$(object, function(key, val) { return obj[key]; });
+ Object.filter$(object, function (key, val) { return Object.hasOwnProperty.call(obj, key) });
+ Object.map$(object, function (key, val) { return obj[key]; });
- Object.keys(obj).diff(Object.keys(object)).forEach(function(key) {
+ Object.keys(obj).diff(Object.keys(object)).forEach(function (key) {
Object.value(object, key, obj[key]);
});
@@ -458,7 +462,7 @@ extend(Object, {
* @param callback|array The callback to call on each property or an array of keys.
* @param scope The value of this in the callback function.
* @example
- * Object.filter({1:2,3:4,5:6}, function(key, val, object) {
+ * Object.filter({1:2,3:4,5:6}, function (key, val, object) {
* return key == 3;
* });
* // returns {3:4}
@@ -483,7 +487,7 @@ extend(Object, {
* @param scope The value of this in the callback function.
* @example
* var obj = {1:2,3:4,5:6};
- * Object.filter$(obj, function(key, val, object) {
+ * Object.filter$(obj, function (key, val, object) {
* return key == 3;
* });
* // obj = {3:4}
@@ -496,7 +500,7 @@ extend(Object, {
* @returns self
*/
if (Array.isArray(callback)) var keys = callback.invoke('toString');
- Object.forEach(obj, function(key, val) {
+ Object.forEach(obj, function (key, val) {
if (Array.isArray(callback)) {
if ( ! keys.contains(key))
Object.remove(obj, key);
@@ -521,7 +525,7 @@ extend(Object, {
*
* @returns object
*/
- return Object.filter(obj, function(key, val) {
+ return Object.filter(obj, function (key, val) {
return !! val;
});
@@ -540,7 +544,7 @@ extend(Object, {
*
* @returns object
*/
- return Object.filter$(obj, function(key, val) {
+ return Object.filter$(obj, function (key, val) {
return !! val;
});
@@ -579,7 +583,7 @@ extend(Object, {
*/
var obj = {};
- keys.forEach(function(key, i) {
+ keys.forEach(function (key, i) {
obj[key] = values[i];
});
@@ -620,7 +624,7 @@ extend(Object, {
*/
return Object.defineProperties(object, {
- size: { value: function() {
+ size: { value: function () {
return Object.size(this);
}, writable: true, enumerable: false, configurable: true },
@@ -762,7 +766,7 @@ if ( ! Object.create) {
var object = {};
if (prototype !== null) {
- var type = function() {}
+ var type = function () {}
type.prototype = prototype;
object = new type();
}
@@ -777,7 +781,7 @@ if ( ! Object.create) {
}
if ( ! Object.defineProperty || domDefineProperty) {
- var oldDefineProperty = Object.defineProperty, definePropertyError = function(object, name, descriptor) {
+ var oldDefineProperty = Object.defineProperty, definePropertyError = function (object, name, descriptor) {
if ( ! Object.isObject(descriptor)) return 'Property description must be an object: ' + descriptor;
if ( ! Object.isObject(object)) return 'Object.defineProperty called on non-object';
@@ -887,7 +891,7 @@ if ( ! Object.keys)
for (key in object)
if (object.hasOwnProperty(key))
keys.push(key);
- keys = keys.filter(function(key) {
+ keys = keys.filter(function (key) {
return Object.prototype.propertyIsEnumerable.call(object, key);
});
View
2  lib/repl.js
@@ -1,5 +1,5 @@
if (typeof module !== 'undefined' && module.exports) {
- module.exports.repl = function() {
+ module.exports.repl = function () {
var vm = require('vm'), repl = require('repl');
process.stdin.removeAllListeners('keypress');
var ctx = repl.start('toolkit> ').context;
View
10 lib/string.js
@@ -26,7 +26,7 @@ extend(String, {
*
* @returns string
*/
- return Array.range(0, 35).map(function(i) {
+ return Array.range(0, 35).map(function (i) {
switch (i) {
case 8:
case 13:
@@ -178,7 +178,7 @@ extend(String.prototype, {
*
* @returns string
*/
- return this.chars().map(function(a) {
+ return this.chars().map(function (a) {
return /[a-z]/.test(a) ? a.toUpperCase() : a.toLowerCase();
}).join('');
@@ -349,7 +349,7 @@ extend(String.prototype, {
*
* @returns string
*/
- this.chars().chunk(len).map(function(chars) {
+ this.chars().chunk(len).map(function (chars) {
return chars.join('');
});
},
@@ -395,7 +395,7 @@ extend(String.prototype, {
* // returns 'Hello World'
*/
var key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', output = '', input = this;
- return input.split("\n").map(function(line) {
+ return input.split("\n").map(function (line) {
var output = '';
for (i = 0; i < line.length; i += 4) {
var e1 = key.indexOf(line.charAt(i)),
@@ -431,7 +431,7 @@ extend(String.prototype, {
var vals = arguments, regex = /%%|%(?:(\d+)[\$#])?([+-])?('.|0| )?(\d*)(?:\.(\d+))?([bcdfosuxX])/g;
var index = 0;
- return this.replace(regex, function(substr, flags, align, padding, width, precision, type) {
+ return this.replace(regex, function (substr, flags, align, padding, width, precision, type) {
if (substr == '%%') return '%';
View
153 test/array.js
@@ -1,22 +1,6 @@
module('Array');
-
-test('Array.diff', function() {
- strictEqual(Array.diff.name, 'diff');
- deepEqual(Array.diff([[1,2,3],[2,3,4],[3,4,5]]), [1,5]);
- deepEqual(Array.diff([1,2,3],[2,3,4],[3,4,5]), [1,5]);
- deepEqual(Array.diff([]), []);
- deepEqual(Array.diff(), []);
-});
-
-test('Array.union', function() {
- strictEqual(Array.union.name, 'union', 'Function Name');
- deepEqual(Array.union([[1,2,3],[2,3,4],[3,4,5]]), [1,2,3,4,5]);
- deepEqual(Array.union([1,2,3],[2,3,4],[3,4,5]), [1,2,3,4,5]);
- deepEqual(Array.union([]), []);
- deepEqual(Array.union(), []);
-});
-
-test('Array.range', function() {
+
+test('Array.range', function () {
var $R = Array.range;
strictEqual($R.name, 'range'); // 1
deepEqual($R(3), [1,2,3]); // 2
@@ -26,13 +10,13 @@ test('Array.range', function() {
deepEqual($R('3',5,'1'), [3,4,5]); // 6
deepEqual($R(3,-2,-2), [3,1,-1]); // 7
deepEqual($R(-3), [-1,-2,-3]); // 8
- raises(function() { $R(1,2,0) }, RangeError); // 9
- raises(function() { $R(1,2,-1) }, RangeError); // 10
- raises(function() { $R(1,-1,1) }, RangeError); // 11
- raises(function() { $R(-1,1,'a') }, RangeError); // 12
+ raises(function () { $R(1,2,0) }, RangeError); // 9
+ raises(function () { $R(1,2,-1) }, RangeError); // 10
+ raises(function () { $R(1,-1,1) }, RangeError); // 11
+ raises(function () { $R(-1,1,'a') }, RangeError); // 12
});
-test('Array#concat$', function() {
+test('Array#concat$', function () {
var arr = [1,2,3];
strictEqual(arr.concat$.name, 'concat$');
strictEqual(arr.concat$(4,5,6), arr);
@@ -40,7 +24,7 @@ test('Array#concat$', function() {
deepEqual(arr.concat$(), [1,2,3,4,5,6]);
});
-test('Array#swap', function() {
+test('Array#swap', function () {
// Rest of the tests are covered by swap$
var arr = [1,2,3];
strictEqual(arr.swap.name, 'swap');
@@ -48,26 +32,26 @@ test('Array#swap', function() {
deepEqual(arr.swap(2, 0), [3,2,1]);
});
-test('Array#swap$', function() {
+test('Array#swap$', function () {
var arr = [1,2,3];
strictEqual(arr.swap$.name, 'swap$'); // 1
strictEqual(arr.swap$(2,0), arr); // 2
deepEqual(arr,[3,2,1]); // 3
deepEqual([1,2,3].swap$(2,'0'), [3,2,1]); // 4
- raises(function() { [1,2,3].swap$(1,3) }, RangeError); // 5
- raises(function() { [1,2,3].swap$(-1,2) }, RangeError); // 6
- raises(function() { [1,2,3].swap$() }, RangeError); // 7
- raises(function() { [1,2,3].swap$(1,'length') }, RangeError); // 8
+ raises(function () { [1,2,3].swap$(1,3) }, RangeError); // 5
+ raises(function () { [1,2,3].swap$(-1,2) }, RangeError); // 6
+ raises(function () { [1,2,3].swap$() }, RangeError); // 7
+ raises(function () { [1,2,3].swap$(1,'length') }, RangeError); // 8
arr.foo = 'bar';
- raises(function() { arr.swap$(0,'foo') }, RangeError); // 9
+ raises(function () { arr.swap$(0,'foo') }, RangeError); // 9
arr = new Array(5);
arr[3] = 2, arr[1] = 1;
deepEqual(arr.swap$(1,3), [,2,,1,,]); // 10
});
-test('Array#contains', function() {
+test('Array#contains', function () {
strictEqual([].contains.name, 'contains'); // 1
ok([1,2,3].contains(1,2)); // 2
strictEqual([1,2,3].contains(4), false); // 3
@@ -75,7 +59,7 @@ test('Array#contains', function() {
strictEqual([].contains(2), false); // 5
});
-test('Array#remove', function() {
+test('Array#remove', function () {
var a = [1,2,3];
strictEqual(a.remove.name, 'remove');
ok(a.remove(2,3) !== a);
@@ -83,7 +67,7 @@ test('Array#remove', function() {
// Further testing is done in #remove$
});
-test('Array#remove$', function() {
+test('Array#remove$', function () {
var arr = [1,2,3];
arr.foo = 'bar';
@@ -97,14 +81,14 @@ test('Array#remove$', function() {
deepEqual([].remove$(1,2), []);
});
-test('Array#shuffle', function() {
+test('Array#shuffle', function () {
var a = [1,2,3], b = a.shuffle();
strictEqual(a.shuffle.name, 'shuffle');
notStrictEqual(b, a);
ok(a.contains(1,2,3));
});
-test('Array#shuffle$', function() {
+test('Array#shuffle$', function () {
var a = [1,2,3], b = a.shuffle$();
strictEqual(a.shuffle$.name, 'shuffle$');
strictEqual(a, b);
@@ -112,49 +96,59 @@ test('Array#shuffle$', function() {
});
-test('Array#clone', function() {
+test('Array#clone', function () {
var a = [1,2,3], b = a.clone();
notStrictEqual(a, b);
deepEqual(a, b)
});
-test('Array#intersect', function() {
+test('Array#intersect', function () {
strictEqual([].intersect.name, 'intersect');
- strictEqual([].intersection.name, 'intersection');
+ strictEqual(Array.prototype.intersection, Array.prototype.intersect);
var a = [1,2,3], b = [2,3,4], c = [3,4,5]
deepEqual(a.intersect(b,c), [3]);
-
- deepEqual(Array.intersect([[1,2,3],[2,3,4],[3,4,5]]), [3]);
- deepEqual(Array.intersect([1,2,3],[2,3,4],[3,4,5]), [3]);
- deepEqual(Array.intersect([]), []);
- deepEqual(Array.intersect(), []);
+ deepEqual([a,b,c].intersect(), [3]);
+ deepEqual(a.intersect(1), a);
+ deepEqual([].intersect(), []);
});
-test('Array#diff', function() {
+test('Array#diff', function () {
+ strictEqual(Array.prototype.diff.name, 'diff');
var a = [1,2,3], b = [2,3,4], c = [3,4,5]
- deepEqual(a.diff(b,c), [5,1]);
+ deepEqual(a.diff(b,c), [1,5]);
+ deepEqual([a,b,c].diff(), [1,5]);
+ deepEqual([].diff(), []);
+ deepEqual([a].diff(2,[3,4]), [1,4]);
+});
+
+test('Array#union', function () {
+ strictEqual(Array.prototype.union.name, 'union');
+ var a = [1,2,3], b = [3,4,5], c = [5,6,7];
+ deepEqual(a.union(b,c), [1,2,3,4,5,6,7]);
+ deepEqual([[1,2,3],[2,3,4],[3,4,5]].union(), [1,2,3,4,5]);
+ deepEqual([].union(), []);
});
-test('Array#chunk', function() {
+test('Array#chunk', function () {
var $R = Array.range;
deepEqual($R(12).chunk(3), [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]);
deepEqual($R(12).chunk(7), [[1,2,3,4,5,6,7],[8,9,10,11,12]]);
deepEqual($R(12).chunk(13), [[1,2,3,4,5,6,7,8,9,10,11,12]]);
});
-test('Array#chunk$', function() {
+test('Array#chunk$', function () {
var $R = Array.range, a = $R(12);
strictEqual(a.chunk$(3), a);
deepEqual(a, [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]);
});
-test('Array#unique', function() {
+test('Array#unique', function () {
deepEqual([1,2,2].unique(), [1,2]);
});
-test('Array#forEach', function() {
- var j = 0, r = [1,2,3].each(function(i) {
+test('Array#forEach', function () {
+ var j = 0, r = [1,2,3].each(function (i) {
j = i; if (i == 2) return 3;
});
@@ -162,82 +156,77 @@ test('Array#forEach', function() {
strictEqual(r,3);
});
-test('Array#flatten', function() {
+test('Array#flatten', function () {
deepEqual([1,2,[[3]]].flatten(), [1,2,3]);
deepEqual([1,2,[[3]]].flatten(1), [1,2,[3]]);
});
-test('Array#flatten$', function() {
+test('Array#flatten$', function () {
var a = [1,2,[[3]]];
strictEqual(a.flatten$(1), a);
deepEqual(a, [1,2,[3]]);
});
-test('Array#sum', function() {
+test('Array#sum', function () {
strictEqual([3,4,5].sum(), 12);
strictEqual([3,'4',5].sum(), 12);
});
-test('Array#product', function() {
+test('Array#product', function () {
strictEqual([3,4,5].product(), 60);
strictEqual([3,'4',5].product(), 60);
});
-test('Array#first', function() {