array-tools
Advanced tools
Comparing version 2.0.0-1 to 2.0.0-2
#!/usr/bin/env node | ||
"use strict"; | ||
var a = require("../"); | ||
var tr = require("transform-tools"); | ||
var domain = require("domain"); | ||
var ansi = require("ansi-escape-sequences"); | ||
var util = require("util"); | ||
@@ -16,3 +18,15 @@ if (process.argv.length < 4){ | ||
var args = process.argv.slice(0); | ||
args = args.map(function(arg){ | ||
return arg.replace(/\\n/g, "\n"); | ||
}); | ||
switch (method){ | ||
/* convert map arg to a function */ | ||
case "map": | ||
var funcBody = args.shift(); | ||
var mapFunction = new Function("item", funcBody); | ||
args.unshift(mapFunction); | ||
break; | ||
} | ||
function processInput(input){ | ||
@@ -22,7 +36,20 @@ var arr = a(input); | ||
if (result._data) result = result.val(); | ||
return JSON.stringify(result, null, " ") + "\n"; | ||
/* certain methods don't output JSON */ | ||
if (a.contains([ "join" ], method)){ | ||
return result + "\n"; | ||
} else { | ||
return JSON.stringify(result, null, " ") + "\n"; | ||
} | ||
} | ||
var d = domain.create(); | ||
d.on("error", function(err){ | ||
if (err.code === "EPIPE") return; // don't care | ||
console.error(ansi.format("Error: " + err.stack, "red")); | ||
}); | ||
d.run(function(){ | ||
process.stdin | ||
.pipe(tr.collectJson({ transform: processInput })) | ||
.pipe(tr.collectJson({ through: processInput })) | ||
.pipe(process.stdout); | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(r){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.arrayTools=r()}}(function(){var define,module,exports;return function r(t,e,n){function o(u,a){if(!e[u]){if(!t[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=e[u]={exports:{}};t[u][0].call(c.exports,function(r){var e=t[u][1][r];return o(e?e:r)},c,c.exports,r,t,e,n)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(require,module,exports){"use strict";function ArrayTools(r){return this instanceof ArrayTools?void(this._data=r):new ArrayTools(r)}function arrayify(r){return void 0===r?[]:t.isArrayLike(r)?Array.prototype.slice.call(r):Array.isArray(r)?r:[r]}function where(r,t){return r=arrayify(r),r.filter(function(r){return testValue(r,t)})}function without(r,t){return t=arrayify(t),r.filter(function(r){return!testValue(r,t)})}function testValue(r,e){if(t.isPlainObject(e))return o.exists(r,e);if(Array.isArray(e)){var n=e;return n.some(function(t){return testValue(r,t)})}return e instanceof RegExp?e.test(r):"function"==typeof e?e(r):e===r}function exists(r,t){return r.some(function(r){return testValue(r,t)})}function pluck(recordset,property,property2,property3){if(!Array.isArray(recordset))throw new Error(".pluck() input must be an array");return recordset.filter(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three}).map(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three})}function pick(){var r=arrayify(arguments),t=r.shift(),e=r;if(!Array.isArray(t))throw new Error(".pick() input must be an array");return t.filter(function(r){return e.some(function(t){return void 0!==r[t]})}).map(function(r){var t={};return e.forEach(function(e){void 0!==r[e]&&(t[e]=r[e])}),t})}function findWhere(r,t){var e=where(r,t);return e.length?e[0]:null}function union(r,t,e){var n=o.clone(r);return t.forEach(function(r){if(e){var t={};t[e]=r[e],findWhere(n,t)||n.push(r)}else exists(n,r)||n.push(r)}),n}function commonSequence(r,t){for(var e=[],n=0;n<Math.min(r.length,t.length)&&r[n]===t[n];n++)e.push(r[n]);return e}function unique(r){return r.reduce(function(r,t){return-1===r.indexOf(t)&&r.push(t),r},[])}function spliceWhile(r,t,e){for(var n=0;n<r.length&&e.test(r[n]);n++);var o=[t,n];return o=o.concat(arrayify(arguments).slice(3)),r.splice.apply(r,o)}function extract(r,e){var n=[],i=[];arrayify(r).forEach(function(r,u){t.isPlainObject(e)?o.exists(r,e)&&(n.push(r),i.push(u)):e(r)&&(n.push(r),i.push(u))});for(var u=0;u<i.length;u++)r.splice(i[u]-u,1);return n}function flatten(r){return arrayify(r).reduce(function(r,t){return r.concat(t)},[])}function sortBy(r,t,e){return r.sort(sortByFunc(arrayify(t),e))}function sortByFunc(r,t){var e=r.slice(0),n=e.shift();return function o(i,u){var a,s=i[n],f=u[n];return a="undefined"==typeof s&&"undefined"!=typeof f?-1:"undefined"!=typeof s&&"undefined"==typeof f?1:"undefined"==typeof s&&"undefined"==typeof f?0:t&&t[n]?t[n].indexOf(s)-t[n].indexOf(f):f>s?-1:s>f?1:0,0===a?e.length?(n=e.shift(),o(i,u)):0:(e=r.slice(0),n=e.shift(),a)}}function last(r){return r[r.length-1]}function remove(r,t){return r.splice(r.indexOf(t),1)[0]}function contains(r,t){return Array.isArray(r)&&!Array.isArray(t)?r.indexOf(t)>-1:Array.isArray(r)&&Array.isArray(t)?t.every(function(t){return contains(r,t)}):r===t}module.exports=ArrayTools;var t=require("typical"),o=require("object-tools"),util=require("util");ArrayTools.pluck=pluck,ArrayTools.pick=pick,ArrayTools.commonSequence=commonSequence,ArrayTools.arrayify=arrayify,ArrayTools.exists=exists,ArrayTools.without=without,ArrayTools.union=union,ArrayTools.where=where,ArrayTools.findWhere=findWhere,ArrayTools.unique=unique,ArrayTools.spliceWhile=spliceWhile,ArrayTools.extract=extract,ArrayTools.flatten=flatten,ArrayTools.sortBy=sortBy,ArrayTools.last=last,ArrayTools.remove=remove,ArrayTools.contains=contains,ArrayTools.testValue=testValue,ArrayTools.prototype.val=function(){return this._data},["filter","reverse","sort","concat","slice","every","some","map"].forEach(function(r){ArrayTools.prototype[r]=function(){return this._data=Array.prototype[r].apply(this._data,arguments),this}}),["join"].forEach(function(r){ArrayTools.prototype[r]=function(){return Array.prototype[r].apply(this._data,arguments)}}),["pluck","pick","arrayify","where","without","unique","spliceWhile","extract","flatten","sortBy"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),this._data=ArrayTools[r].apply(null,t),this}}),["exists","findWhere","last","remove","contains"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),ArrayTools[r].apply(null,t)}})},{"object-tools":6,typical:12,util:5}],2:[function(r,t){t.exports="function"==typeof Object.create?function(r,t){r.super_=t,r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}})}:function(r,t){r.super_=t;var e=function(){};e.prototype=t.prototype,r.prototype=new e,r.prototype.constructor=r}},{}],3:[function(r,t){function e(){f=!1,u.length?s=u.concat(s):c=-1,s.length&&n()}function n(){if(!f){var r=setTimeout(e);f=!0;for(var t=s.length;t;){for(u=s,s=[];++c<t;)u[c].run();c=-1,t=s.length}u=null,f=!1,clearTimeout(r)}}function o(r,t){this.fun=r,this.array=t}function i(){}var u,a=t.exports={},s=[],f=!1,c=-1;a.nextTick=function(r){var t=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)t[e-1]=arguments[e];s.push(new o(r,t)),1!==s.length||f||setTimeout(n,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=i,a.addListener=i,a.once=i,a.off=i,a.removeListener=i,a.removeAllListeners=i,a.emit=i,a.binding=function(){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},{}],4:[function(r,t){t.exports=function(r){return r&&"object"==typeof r&&"function"==typeof r.copy&&"function"==typeof r.fill&&"function"==typeof r.readUInt8}},{}],5:[function(r,t,e){(function(t,n){function o(r,t){var n={seen:[],stylize:u};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),d(t)?n.showHidden=t:t&&e._extend(n,t),w(n.showHidden)&&(n.showHidden=!1),w(n.depth)&&(n.depth=2),w(n.colors)&&(n.colors=!1),w(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=i),s(n,r,n.depth)}function i(r,t){var e=o.styles[t];return e?"["+o.colors[e][0]+"m"+r+"["+o.colors[e][1]+"m":r}function u(r){return r}function a(r){var t={};return r.forEach(function(r){t[r]=!0}),t}function s(r,t,n){if(r.customInspect&&t&&E(t.inspect)&&t.inspect!==e.inspect&&(!t.constructor||t.constructor.prototype!==t)){var o=t.inspect(n,r);return A(o)||(o=s(r,o,n)),o}var i=f(r,t);if(i)return i;var u=Object.keys(t),d=a(u);if(r.showHidden&&(u=Object.getOwnPropertyNames(t)),O(t)&&(u.indexOf("message")>=0||u.indexOf("description")>=0))return c(t);if(0===u.length){if(E(t)){var v=t.name?": "+t.name:"";return r.stylize("[Function"+v+"]","special")}if(x(t))return r.stylize(RegExp.prototype.toString.call(t),"regexp");if(T(t))return r.stylize(Date.prototype.toString.call(t),"date");if(O(t))return c(t)}var g="",m=!1,b=["{","}"];if(h(t)&&(m=!0,b=["[","]"]),E(t)){var w=t.name?": "+t.name:"";g=" [Function"+w+"]"}if(x(t)&&(g=" "+RegExp.prototype.toString.call(t)),T(t)&&(g=" "+Date.prototype.toUTCString.call(t)),O(t)&&(g=" "+c(t)),0===u.length&&(!m||0==t.length))return b[0]+g+b[1];if(0>n)return x(t)?r.stylize(RegExp.prototype.toString.call(t),"regexp"):r.stylize("[Object]","special");r.seen.push(t);var j;return j=m?l(r,t,n,d,u):u.map(function(e){return y(r,t,n,d,e,m)}),r.seen.pop(),p(j,g,b)}function f(r,t){if(w(t))return r.stylize("undefined","undefined");if(A(t)){var e="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return r.stylize(e,"string")}return m(t)?r.stylize(""+t,"number"):d(t)?r.stylize(""+t,"boolean"):v(t)?r.stylize("null","null"):void 0}function c(r){return"["+Error.prototype.toString.call(r)+"]"}function l(r,t,e,n,o){for(var i=[],u=0,a=t.length;a>u;++u)i.push(W(t,String(u))?y(r,t,e,n,String(u),!0):"");return o.forEach(function(o){o.match(/^\d+$/)||i.push(y(r,t,e,n,o,!0))}),i}function y(r,t,e,n,o,i){var u,a,f;if(f=Object.getOwnPropertyDescriptor(t,o)||{value:t[o]},f.get?a=f.set?r.stylize("[Getter/Setter]","special"):r.stylize("[Getter]","special"):f.set&&(a=r.stylize("[Setter]","special")),W(n,o)||(u="["+o+"]"),a||(r.seen.indexOf(f.value)<0?(a=v(e)?s(r,f.value,null):s(r,f.value,e-1),a.indexOf("\n")>-1&&(a=i?a.split("\n").map(function(r){return" "+r}).join("\n").substr(2):"\n"+a.split("\n").map(function(r){return" "+r}).join("\n"))):a=r.stylize("[Circular]","special")),w(u)){if(i&&o.match(/^\d+$/))return a;u=JSON.stringify(""+o),u.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=r.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=r.stylize(u,"string"))}return u+": "+a}function p(r,t,e){var n=0,o=r.reduce(function(r,t){return n++,t.indexOf("\n")>=0&&n++,r+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return o>60?e[0]+(""===t?"":t+"\n ")+" "+r.join(",\n ")+" "+e[1]:e[0]+t+" "+r.join(", ")+" "+e[1]}function h(r){return Array.isArray(r)}function d(r){return"boolean"==typeof r}function v(r){return null===r}function g(r){return null==r}function m(r){return"number"==typeof r}function A(r){return"string"==typeof r}function b(r){return"symbol"==typeof r}function w(r){return void 0===r}function x(r){return j(r)&&"[object RegExp]"===k(r)}function j(r){return"object"==typeof r&&null!==r}function T(r){return j(r)&&"[object Date]"===k(r)}function O(r){return j(r)&&("[object Error]"===k(r)||r instanceof Error)}function E(r){return"function"==typeof r}function _(r){return null===r||"boolean"==typeof r||"number"==typeof r||"string"==typeof r||"symbol"==typeof r||"undefined"==typeof r}function k(r){return Object.prototype.toString.call(r)}function q(r){return 10>r?"0"+r.toString(10):r.toString(10)}function S(){var r=new Date,t=[q(r.getHours()),q(r.getMinutes()),q(r.getSeconds())].join(":");return[r.getDate(),N[r.getMonth()],t].join(" ")}function W(r,t){return Object.prototype.hasOwnProperty.call(r,t)}var B=/%[sdj%]/g;e.format=function(r){if(!A(r)){for(var t=[],e=0;e<arguments.length;e++)t.push(o(arguments[e]));return t.join(" ")}for(var e=1,n=arguments,i=n.length,u=String(r).replace(B,function(r){if("%%"===r)return"%";if(e>=i)return r;switch(r){case"%s":return String(n[e++]);case"%d":return Number(n[e++]);case"%j":try{return JSON.stringify(n[e++])}catch(t){return"[Circular]"}default:return r}}),a=n[e];i>e;a=n[++e])u+=v(a)||!j(a)?" "+a:" "+o(a);return u},e.deprecate=function(r,o){function i(){if(!u){if(t.throwDeprecation)throw new Error(o);t.traceDeprecation?console.trace(o):console.error(o),u=!0}return r.apply(this,arguments)}if(w(n.process))return function(){return e.deprecate(r,o).apply(this,arguments)};if(t.noDeprecation===!0)return r;var u=!1;return i};var z,D={};e.debuglog=function(r){if(w(z)&&(z=t.env.NODE_DEBUG||""),r=r.toUpperCase(),!D[r])if(new RegExp("\\b"+r+"\\b","i").test(z)){var n=t.pid;D[r]=function(){var t=e.format.apply(e,arguments);console.error("%s %d: %s",r,n,t)}}else D[r]=function(){};return D[r]},e.inspect=o,o.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},o.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=h,e.isBoolean=d,e.isNull=v,e.isNullOrUndefined=g,e.isNumber=m,e.isString=A,e.isSymbol=b,e.isUndefined=w,e.isRegExp=x,e.isObject=j,e.isDate=T,e.isError=O,e.isFunction=E,e.isPrimitive=_,e.isBuffer=r("./support/isBuffer");var N=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];e.log=function(){console.log("%s - %s",S(),e.format.apply(e,arguments))},e.inherits=r("inherits"),e._extend=function(r,t){if(!t||!j(t))return r;for(var e=Object.keys(t),n=e.length;n--;)r[e[n]]=t[e[n]];return r}}).call(this,r("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":4,_process:3,inherits:2}],6:[function(r,t,e){"use strict";function n(){var r=0,t=h.arrayify(arguments);if(!t.length)return{};var e=h(t).last();return d.isPlainObject(e)&&"__depth"in e&&(r=e.__depth,t.pop()),t.reduce(function(t,e){if("object"!=typeof e)return t;for(var o in e){var i=e[o];d.isObject(i)&&!Array.isArray(i)&&10>r?(t[o]||(t[o]={}),t[o]=n(t[o],i,{__depth:++r})):t[o]=i}return t},{})}function o(r){var t;if("object"!=typeof r||Array.isArray(r)||null===r)return Array.isArray(r)?(t=[],r.forEach(function(r){t.push(o(r))}),t):r;t={};for(var e in r)t[e]=r[e];return t}function i(r,t){var e=!0;for(var n in r)e=e&&t(r[n],n);return e}function u(r,t){for(var e in r)t(r[e],e)}function a(r,t){if(2!==arguments.length)throw Error("expecting two args");if(!d.isObject(r))throw Error("input object must be an object: "+r);if(!d.isObject(t))throw Error("query must be an object: "+t);return Object.keys(t).every(function(e){var n=t[e],o=!1,i=!1;"!"===e.charAt(0)?o=!0:"+"===e.charAt(0)&&(i=!0);var u=r[o||i?e.slice(1):e];return i&&(n=h.arrayify(n),u=h.arrayify(u)),"undefined"==typeof u&&u!==n?o:Array.isArray(n)?s(h.exists(u,n),o):n instanceof RegExp?-1===["boolean","string","number"].indexOf(typeof u)?o:s(n.test(u),o):"function"==typeof n?s(n(u),o):d.isObject(u)&&d.isObject(n)?s(a(u,n),o):s(n===u,o)})}function s(r,t){return t?!r:r}function f(r,t){t=h.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function c(r,t){var e={};if("function"==typeof t)for(var n in r)t(r[n],n)===!0&&(e[n]=r[n]);else if(Array.isArray(t))for(var n in r)t.indexOf(n)>-1&&(e[n]=r[n]);return e}function l(r,t){var e=c(r,t);for(var n in e)delete r[n];return e}function y(r,t){return t.reduce(function(t,e){return t[e]=r[e],t},{})}function p(r,t){return t.trim().split(".").reduce(function(r,t){return r&&r[t]},r)}{var h=r("array-tools"),d=r("typical");r("util")}e.extend=n,e.clone=o,e.every=i,e.each=u,e.exists=a,e.without=f,e.extract=l,e.where=c,e.select=y,e.get=p},{"array-tools":7,typical:11,util:5}],7:[function(require,module,exports){"use strict";function ArrayTools(r){return this instanceof ArrayTools?void(this._data=r):new ArrayTools(r)}function arrayify(r){return void 0===r?[]:t.isArrayLike(r)?Array.prototype.slice.call(r):Array.isArray(r)?r:[r]}function where(r,t){return arrayify(r).filter(function(r){return o.exists(r,t)})}function exists(r,e){if(t.isPlainObject(e)){var n=e;return r.some(function(r){return o.exists(r,n)})}return Array.isArray(e)?e.every(function(t){return exists(r,t)}):e instanceof RegExp?r.some(function(r){return e.test(r)}):"function"==typeof e?r.some(function(r){return e(r)}):contains(r,e)}function pluck(recordset,property,property2,property3){if(!Array.isArray(recordset))throw new Error(".pluck() input must be an array");return recordset.filter(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three}).map(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three})}function pick(){var r=arrayify(arguments),t=r.shift(),e=r;if(!Array.isArray(t))throw new Error(".pick() input must be an array");return t.filter(function(r){return e.some(function(t){return void 0!==r[t]})}).map(function(r){var t={};return e.forEach(function(e){void 0!==r[e]&&(t[e]=r[e])}),t})}function findWhere(r,t){var e=where(r,t);return e.length?e[0]:null}function without(r,t){return t=arrayify(t),r.filter(function(r){return!exists(t,r)})}function union(r,t,e){var n=o.clone(r);return t.forEach(function(r){if(e){var t={};t[e]=r[e],findWhere(n,t)||n.push(r)}else exists(n,r)||n.push(r)}),n}function commonSequence(r,t){for(var e=[],n=0;n<Math.min(r.length,t.length)&&r[n]===t[n];n++)e.push(r[n]);return e}function unique(r){return r.reduce(function(r,t){return-1===r.indexOf(t)&&r.push(t),r},[])}function spliceWhile(r,t,e){for(var n=0;n<r.length&&e.test(r[n]);n++);var o=[t,n];return o=o.concat(arrayify(arguments).slice(3)),r.splice.apply(r,o)}function extract(r,e){var n=[],i=[];arrayify(r).forEach(function(r,u){t.isPlainObject(e)?o.exists(r,e)&&(n.push(r),i.push(u)):e(r)&&(n.push(r),i.push(u))});for(var u=0;u<i.length;u++)r.splice(i[u]-u,1);return n}function flatten(r){return arrayify(r).reduce(function(r,t){return r.concat(t)},[])}function sortBy(r,t,e){return r.sort(sortByFunc(arrayify(t),e))}function sortByFunc(r,t){var e=r.slice(0),n=e.shift();return function o(i,u){var a,s=i[n],f=u[n];return a="undefined"==typeof s&&"undefined"!=typeof f?-1:"undefined"!=typeof s&&"undefined"==typeof f?1:"undefined"==typeof s&&"undefined"==typeof f?0:t&&t[n]?t[n].indexOf(s)-t[n].indexOf(f):f>s?-1:s>f?1:0,0===a?e.length?(n=e.shift(),o(i,u)):0:(e=r.slice(0),n=e.shift(),a)}}function last(r){return r[r.length-1]}function remove(r,t){return r.splice(r.indexOf(t),1)[0]}function contains(r,t){return r.indexOf(t)>-1}module.exports=ArrayTools;var t=require("typical"),o=require("object-tools"),util=require("util");ArrayTools.pluck=pluck,ArrayTools.pick=pick,ArrayTools.commonSequence=commonSequence,ArrayTools.arrayify=arrayify,ArrayTools.exists=exists,ArrayTools.without=without,ArrayTools.union=union,ArrayTools.where=where,ArrayTools.findWhere=findWhere,ArrayTools.unique=unique,ArrayTools.spliceWhile=spliceWhile,ArrayTools.extract=extract,ArrayTools.flatten=flatten,ArrayTools.sortBy=sortBy,ArrayTools.last=last,ArrayTools.remove=remove,ArrayTools.contains=contains,ArrayTools.prototype.val=function(){return this._data},["filter","reverse","sort","concat","slice","every","some","map"].forEach(function(r){ArrayTools.prototype[r]=function(){return this._data=Array.prototype[r].apply(this._data,arguments),this}}),["join"].forEach(function(r){ArrayTools.prototype[r]=function(){return Array.prototype[r].apply(this._data,arguments)}}),["pluck","pick","arrayify","where","without","unique","spliceWhile","extract","flatten","sortBy"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),this._data=ArrayTools[r].apply(null,t),this}}),["exists","findWhere","last","remove","contains"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),ArrayTools[r].apply(null,t)}})},{"object-tools":8,typical:11,util:5}],8:[function(r,t,e){arguments[4][6][0].apply(e,arguments)},{"array-tools":9,dup:6,typical:11,util:5}],9:[function(require,module,exports){"use strict";function ArrayTools(r){return this instanceof ArrayTools?void(this._data=r):new ArrayTools(r)}function arrayify(r){return null===r||void 0===r?[]:t.isArrayLike(r)?Array.prototype.slice.call(r):Array.isArray(r)?r:[r]}function where(r,t){return arrayify(r).filter(function(r){return o.exists(r,t)})}function pluck(arrayOfObjects,property,property2,property3){if(!Array.isArray(arrayOfObjects))throw new Error(".pluck() input must be an array");return arrayOfObjects.filter(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three}).map(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three})}function pick(){var r=arrayify(arguments),t=r.shift(),e=r;if(!Array.isArray(t))throw new Error(".pick() input must be an array");return t.filter(function(r){return e.some(function(t){return void 0!==r[t]})}).map(function(r){var t={};return e.forEach(function(e){void 0!==r[e]&&(t[e]=r[e])}),t})}function exists(r,e){if(t.isPlainObject(e)){for(var n,i=e,u=!1,a=0;!u&&(n=r[a++]);)u=o.exists(n,i);return u}return r.indexOf(e)>-1}function findWhere(r,t){var e=where(r,t);return e.length?e[0]:null}function without(r,t){return t=arrayify(t),r.filter(function(r){return!exists(t,r)})}function union(r,t,e){var n=o.clone(r);return t.forEach(function(r){if(e){var t={};t[e]=r[e],findWhere(n,t)||n.push(r)}else exists(n,r)||n.push(r)}),n}function commonSequence(r,t){for(var e=[],n=0;n<Math.min(r.length,t.length)&&r[n]===t[n];n++)e.push(r[n]);return e}function unique(r){return r.reduce(function(r,t){return-1===r.indexOf(t)&&r.push(t),r},[])}function spliceWhile(r,t,e){for(var n=0;n<r.length&&e.test(r[n]);n++);var o=[t,n];return o=o.concat(arrayify(arguments).slice(3)),r.splice.apply(r,o)}function extract(r,e){var n=[],i=[];arrayify(r).forEach(function(r,u){t.isPlainObject(e)?o.exists(r,e)&&(n.push(r),i.push(u)):e(r)&&(n.push(r),i.push(u))});for(var u=0;u<i.length;u++)r.splice(i[u]-u,1);return n}function flatten(r){return arrayify(r).reduce(function(r,t){return r.concat(t)},[])}function sortBy(r,t,e){return r.sort(sortByFunc(arrayify(t),e))}function sortByFunc(r,t){var e=r.slice(0),n=e.shift();return function o(i,u){var a,s=i[n],f=u[n];return a="undefined"==typeof s&&"undefined"!=typeof f?-1:"undefined"!=typeof s&&"undefined"==typeof f?1:"undefined"==typeof s&&"undefined"==typeof f?0:t&&t[n]?t[n].indexOf(s)-t[n].indexOf(f):f>s?-1:s>f?1:0,0===a?e.length?(n=e.shift(),o(i,u)):0:(e=r.slice(0),n=e.shift(),a)}}function last(r){return r[r.length-1]}function remove(r,t){return r.splice(r.indexOf(t),1)[0]}function contains(r,t){return r.indexOf(t)>-1}module.exports=ArrayTools;var t=require("typical"),o=require("object-tools"),util=require("util");ArrayTools.pluck=pluck,ArrayTools.pick=pick,ArrayTools.commonSequence=commonSequence,ArrayTools.arrayify=arrayify,ArrayTools.exists=exists,ArrayTools.without=without,ArrayTools.union=union,ArrayTools.where=where,ArrayTools.findWhere=findWhere,ArrayTools.unique=unique,ArrayTools.spliceWhile=spliceWhile,ArrayTools.extract=extract,ArrayTools.flatten=flatten,ArrayTools.sortBy=sortBy,ArrayTools.last=last,ArrayTools.remove=remove,ArrayTools.contains=contains,ArrayTools.prototype.val=function(){return this._data},["filter","reverse","sort","concat","slice","every","some","map"].forEach(function(r){ArrayTools.prototype[r]=function(){return this._data=Array.prototype[r].apply(this._data,arguments),this}}),["join"].forEach(function(r){ArrayTools.prototype[r]=function(){return Array.prototype[r].apply(this._data,arguments)}}),["pluck","pick","arrayify","where","without","unique","spliceWhile","extract","flatten","sortBy"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),this._data=ArrayTools[r].apply(null,t),this}}),["exists","findWhere","last","remove","contains"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),ArrayTools[r].apply(null,t)}})},{"object-tools":10,typical:11,util:5}],10:[function(r,t,e){"use strict";function n(){var r=0,t=d.arrayify(arguments);if(!t.length)return{};var e=d(t).last();return v.isPlainObject(e)&&"__depth"in e&&(r=e.__depth,t.pop()),t.reduce(function(t,e){if("object"!=typeof e)return t;for(var o in e){var i=e[o];v.isObject(i)&&!Array.isArray(i)&&10>r?(t[o]||(t[o]={}),t[o]=n(t[o],i,{__depth:++r})):t[o]=i}return t},{})}function o(r){var t;if("object"!=typeof r||Array.isArray(r)||null===r)return Array.isArray(r)?(t=[],r.forEach(function(r){t.push(o(r))}),t):r;t={};for(var e in r)t[e]=r[e];return t}function i(r,t){t=d.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function u(r,t){var e=!0;for(var n in r)e=e&&t(r[n],n);return e}function a(r,t){for(var e in r)t(r[e],e)}function s(r,t){if(2!==arguments.length)throw Error("expecting two args");if("object"!=typeof t)throw Error("query must be an object");r=r||{};var e,n,o=!0;for(var i in t){var u=!1,a=!1;"!"===i.charAt(0)?u=!0:"+"===i.charAt(0)&&(a=!0);var e=t[i],n=r[u||a?i.slice(1):i];if(a&&(e=d.arrayify(e),n=d.arrayify(n)),Array.isArray(e)?(n=n||[],o=e.every(function(r,t){return s(n[t],r)})):o=e instanceof RegExp?"boolean"!=typeof n&&"string"!=typeof n&&"number"!=typeof n?u:u?!e.test(n):e.test(n):"function"==typeof e?u?!e(n):e(n):v.isObject(n)&&v.isObject(e)?s(n,e):u?e!==n:e===n,!o)break}return o}function f(r,t){t=d.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function c(r){var t={};for(var e in r)void 0!==r[e]&&(t[e]=r[e]);return t}function l(r,t){var e={};if("function"==typeof t)for(var n in r)t(r[n],n)===!0&&(e[n]=r[n]);else if(Array.isArray(t))for(var n in r)t.indexOf(n)>-1&&(e[n]=r[n]);return e}function y(r,t){var e=l(r,t);for(var n in e)delete r[n];return e}function p(r,t){return t.reduce(function(t,e){return t[e]=r[e],t},{})}function h(r,t){return t.trim().split(".").reduce(function(r,t){return r&&r[t]},r)}{var d=r("array-tools"),v=r("typical");r("util")}e.extend=n,e.clone=o,e.defined=c,e.every=u,e.each=a,e.omit=i,e.exists=s,e.without=f,e.extract=y,e.where=l,e.select=p,e.get=h},{"array-tools":9,typical:11,util:5}],11:[function(r,t,e){"use strict";function n(r){return!isNaN(parseFloat(r))&&isFinite(r)}function o(r){return null!==r&&"object"==typeof r&&r.constructor===Object}function i(r){return u(r)&&"number"==typeof r.length}function u(r){return"object"==typeof r&&null!==r}e.isNumber=n,e.isPlainObject=o,e.isArrayLike=i,e.isObject=u},{}],12:[function(r,t,e){arguments[4][11][0].apply(e,arguments)},{dup:11}]},{},[1])(1)}); | ||
!function(r){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.arrayTools=r()}}(function(){var define,module,exports;return function r(t,e,n){function o(u,a){if(!e[u]){if(!t[u]){var f="function"==typeof require&&require;if(!a&&f)return f(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var s=e[u]={exports:{}};t[u][0].call(s.exports,function(r){var e=t[u][1][r];return o(e?e:r)},s,s.exports,r,t,e,n)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(require,module,exports){"use strict";function ArrayTools(r){return this instanceof ArrayTools?void(this._data=r):new ArrayTools(r)}function arrayify(r){return void 0===r?[]:t.isArrayLike(r)?Array.prototype.slice.call(r):Array.isArray(r)?r:[r]}function where(r,t){return r=arrayify(r),r.filter(function(r){return testValue(r,t)})}function without(r,t){return t=arrayify(t),r.filter(function(r){return!testValue(r,t)})}function testValue(r,e){if(t.isPlainObject(e))return o.exists(r,e);if(Array.isArray(e)){var n=e;return n.some(function(t){return testValue(r,t)})}return e instanceof RegExp?e.test(r):"function"==typeof e?e(r):e===r}function exists(r,t){return r.some(function(r){return testValue(r,t)})}function pluck(recordset,property,property2,property3){if(!Array.isArray(recordset))throw new Error(".pluck() input must be an array");return recordset.filter(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three}).map(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three})}function pick(){var r=arrayify(arguments),t=r.shift(),e=r;if(!Array.isArray(t))throw new Error(".pick() input must be an array");return t.filter(function(r){return e.some(function(t){return void 0!==r[t]})}).map(function(r){var t={};return e.forEach(function(e){void 0!==r[e]&&(t[e]=r[e])}),t})}function findWhere(r,t){var e=where(r,t);return e.length?e[0]:null}function union(r,t,e){var n=o.clone(r);return t.forEach(function(r){if(e){var t={};t[e]=r[e],findWhere(n,t)||n.push(r)}else exists(n,r)||n.push(r)}),n}function commonSequence(r,t){for(var e=[],n=0;n<Math.min(r.length,t.length)&&r[n]===t[n];n++)e.push(r[n]);return e}function unique(r){return r.reduce(function(r,t){return-1===r.indexOf(t)&&r.push(t),r},[])}function spliceWhile(r,t,e){for(var n=0;n<r.length&&e.test(r[n]);n++);var o=[t,n];return o=o.concat(arrayify(arguments).slice(3)),r.splice.apply(r,o)}function extract(r,e){var n=[],i=[];arrayify(r).forEach(function(r,u){t.isPlainObject(e)?o.exists(r,e)&&(n.push(r),i.push(u)):e(r)&&(n.push(r),i.push(u))});for(var u=0;u<i.length;u++)r.splice(i[u]-u,1);return n}function flatten(r){return arrayify(r).reduce(function(r,t){return r.concat(t)},[])}function sortBy(r,t,e){return r.sort(sortByFunc(arrayify(t),e))}function sortByFunc(r,t){var e=r.slice(0),n=e.shift();return function o(i,u){var a,f=i[n],c=u[n];return a="undefined"==typeof f&&"undefined"!=typeof c?-1:"undefined"!=typeof f&&"undefined"==typeof c?1:"undefined"==typeof f&&"undefined"==typeof c?0:t&&t[n]?t[n].indexOf(f)-t[n].indexOf(c):c>f?-1:f>c?1:0,0===a?e.length?(n=e.shift(),o(i,u)):0:(e=r.slice(0),n=e.shift(),a)}}function last(r){return r[r.length-1]}function remove(r,t){return r.splice(r.indexOf(t),1)[0]}function contains(r,t){return Array.isArray(r)&&!Array.isArray(t)?r.indexOf(t)>-1:Array.isArray(r)&&Array.isArray(t)?t.every(function(t){return contains(r,t)}):r===t}module.exports=ArrayTools;var t=require("typical"),o=require("object-tools");ArrayTools.pluck=pluck,ArrayTools.pick=pick,ArrayTools.commonSequence=commonSequence,ArrayTools.arrayify=arrayify,ArrayTools.exists=exists,ArrayTools.without=without,ArrayTools.union=union,ArrayTools.where=where,ArrayTools.findWhere=findWhere,ArrayTools.unique=unique,ArrayTools.spliceWhile=spliceWhile,ArrayTools.extract=extract,ArrayTools.flatten=flatten,ArrayTools.sortBy=sortBy,ArrayTools.last=last,ArrayTools.remove=remove,ArrayTools.contains=contains,ArrayTools.prototype.val=function(){return this._data},["filter","reverse","sort","concat","slice","every","some","map"].forEach(function(r){ArrayTools.prototype[r]=function(){return this._data=Array.prototype[r].apply(this._data,arguments),this}}),["join"].forEach(function(r){ArrayTools.prototype[r]=function(){return Array.prototype[r].apply(this._data,arguments)}}),["pluck","pick","arrayify","where","without","unique","spliceWhile","extract","flatten","sortBy"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),this._data=ArrayTools[r].apply(null,t),this}}),["exists","findWhere","last","remove","contains"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),ArrayTools[r].apply(null,t)}})},{"object-tools":6,typical:12}],2:[function(r,t){t.exports="function"==typeof Object.create?function(r,t){r.super_=t,r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}})}:function(r,t){r.super_=t;var e=function(){};e.prototype=t.prototype,r.prototype=new e,r.prototype.constructor=r}},{}],3:[function(r,t){function e(){c=!1,u.length?f=u.concat(f):s=-1,f.length&&n()}function n(){if(!c){var r=setTimeout(e);c=!0;for(var t=f.length;t;){for(u=f,f=[];++s<t;)u[s].run();s=-1,t=f.length}u=null,c=!1,clearTimeout(r)}}function o(r,t){this.fun=r,this.array=t}function i(){}var u,a=t.exports={},f=[],c=!1,s=-1;a.nextTick=function(r){var t=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)t[e-1]=arguments[e];f.push(new o(r,t)),1!==f.length||c||setTimeout(n,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=i,a.addListener=i,a.once=i,a.off=i,a.removeListener=i,a.removeAllListeners=i,a.emit=i,a.binding=function(){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},{}],4:[function(r,t){t.exports=function(r){return r&&"object"==typeof r&&"function"==typeof r.copy&&"function"==typeof r.fill&&"function"==typeof r.readUInt8}},{}],5:[function(r,t,e){(function(t,n){function o(r,t){var n={seen:[],stylize:u};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),d(t)?n.showHidden=t:t&&e._extend(n,t),j(n.showHidden)&&(n.showHidden=!1),j(n.depth)&&(n.depth=2),j(n.colors)&&(n.colors=!1),j(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=i),f(n,r,n.depth)}function i(r,t){var e=o.styles[t];return e?"["+o.colors[e][0]+"m"+r+"["+o.colors[e][1]+"m":r}function u(r){return r}function a(r){var t={};return r.forEach(function(r){t[r]=!0}),t}function f(r,t,n){if(r.customInspect&&t&&E(t.inspect)&&t.inspect!==e.inspect&&(!t.constructor||t.constructor.prototype!==t)){var o=t.inspect(n,r);return b(o)||(o=f(r,o,n)),o}var i=c(r,t);if(i)return i;var u=Object.keys(t),d=a(u);if(r.showHidden&&(u=Object.getOwnPropertyNames(t)),T(t)&&(u.indexOf("message")>=0||u.indexOf("description")>=0))return s(t);if(0===u.length){if(E(t)){var v=t.name?": "+t.name:"";return r.stylize("[Function"+v+"]","special")}if(w(t))return r.stylize(RegExp.prototype.toString.call(t),"regexp");if(O(t))return r.stylize(Date.prototype.toString.call(t),"date");if(T(t))return s(t)}var g="",m=!1,A=["{","}"];if(h(t)&&(m=!0,A=["[","]"]),E(t)){var j=t.name?": "+t.name:"";g=" [Function"+j+"]"}if(w(t)&&(g=" "+RegExp.prototype.toString.call(t)),O(t)&&(g=" "+Date.prototype.toUTCString.call(t)),T(t)&&(g=" "+s(t)),0===u.length&&(!m||0==t.length))return A[0]+g+A[1];if(0>n)return w(t)?r.stylize(RegExp.prototype.toString.call(t),"regexp"):r.stylize("[Object]","special");r.seen.push(t);var x;return x=m?l(r,t,n,d,u):u.map(function(e){return y(r,t,n,d,e,m)}),r.seen.pop(),p(x,g,A)}function c(r,t){if(j(t))return r.stylize("undefined","undefined");if(b(t)){var e="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return r.stylize(e,"string")}return m(t)?r.stylize(""+t,"number"):d(t)?r.stylize(""+t,"boolean"):v(t)?r.stylize("null","null"):void 0}function s(r){return"["+Error.prototype.toString.call(r)+"]"}function l(r,t,e,n,o){for(var i=[],u=0,a=t.length;a>u;++u)i.push(z(t,String(u))?y(r,t,e,n,String(u),!0):"");return o.forEach(function(o){o.match(/^\d+$/)||i.push(y(r,t,e,n,o,!0))}),i}function y(r,t,e,n,o,i){var u,a,c;if(c=Object.getOwnPropertyDescriptor(t,o)||{value:t[o]},c.get?a=c.set?r.stylize("[Getter/Setter]","special"):r.stylize("[Getter]","special"):c.set&&(a=r.stylize("[Setter]","special")),z(n,o)||(u="["+o+"]"),a||(r.seen.indexOf(c.value)<0?(a=v(e)?f(r,c.value,null):f(r,c.value,e-1),a.indexOf("\n")>-1&&(a=i?a.split("\n").map(function(r){return" "+r}).join("\n").substr(2):"\n"+a.split("\n").map(function(r){return" "+r}).join("\n"))):a=r.stylize("[Circular]","special")),j(u)){if(i&&o.match(/^\d+$/))return a;u=JSON.stringify(""+o),u.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=r.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=r.stylize(u,"string"))}return u+": "+a}function p(r,t,e){var n=0,o=r.reduce(function(r,t){return n++,t.indexOf("\n")>=0&&n++,r+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return o>60?e[0]+(""===t?"":t+"\n ")+" "+r.join(",\n ")+" "+e[1]:e[0]+t+" "+r.join(", ")+" "+e[1]}function h(r){return Array.isArray(r)}function d(r){return"boolean"==typeof r}function v(r){return null===r}function g(r){return null==r}function m(r){return"number"==typeof r}function b(r){return"string"==typeof r}function A(r){return"symbol"==typeof r}function j(r){return void 0===r}function w(r){return x(r)&&"[object RegExp]"===k(r)}function x(r){return"object"==typeof r&&null!==r}function O(r){return x(r)&&"[object Date]"===k(r)}function T(r){return x(r)&&("[object Error]"===k(r)||r instanceof Error)}function E(r){return"function"==typeof r}function _(r){return null===r||"boolean"==typeof r||"number"==typeof r||"string"==typeof r||"symbol"==typeof r||"undefined"==typeof r}function k(r){return Object.prototype.toString.call(r)}function q(r){return 10>r?"0"+r.toString(10):r.toString(10)}function S(){var r=new Date,t=[q(r.getHours()),q(r.getMinutes()),q(r.getSeconds())].join(":");return[r.getDate(),N[r.getMonth()],t].join(" ")}function z(r,t){return Object.prototype.hasOwnProperty.call(r,t)}var W=/%[sdj%]/g;e.format=function(r){if(!b(r)){for(var t=[],e=0;e<arguments.length;e++)t.push(o(arguments[e]));return t.join(" ")}for(var e=1,n=arguments,i=n.length,u=String(r).replace(W,function(r){if("%%"===r)return"%";if(e>=i)return r;switch(r){case"%s":return String(n[e++]);case"%d":return Number(n[e++]);case"%j":try{return JSON.stringify(n[e++])}catch(t){return"[Circular]"}default:return r}}),a=n[e];i>e;a=n[++e])u+=v(a)||!x(a)?" "+a:" "+o(a);return u},e.deprecate=function(r,o){function i(){if(!u){if(t.throwDeprecation)throw new Error(o);t.traceDeprecation?console.trace(o):console.error(o),u=!0}return r.apply(this,arguments)}if(j(n.process))return function(){return e.deprecate(r,o).apply(this,arguments)};if(t.noDeprecation===!0)return r;var u=!1;return i};var B,D={};e.debuglog=function(r){if(j(B)&&(B=t.env.NODE_DEBUG||""),r=r.toUpperCase(),!D[r])if(new RegExp("\\b"+r+"\\b","i").test(B)){var n=t.pid;D[r]=function(){var t=e.format.apply(e,arguments);console.error("%s %d: %s",r,n,t)}}else D[r]=function(){};return D[r]},e.inspect=o,o.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},o.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=h,e.isBoolean=d,e.isNull=v,e.isNullOrUndefined=g,e.isNumber=m,e.isString=b,e.isSymbol=A,e.isUndefined=j,e.isRegExp=w,e.isObject=x,e.isDate=O,e.isError=T,e.isFunction=E,e.isPrimitive=_,e.isBuffer=r("./support/isBuffer");var N=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];e.log=function(){console.log("%s - %s",S(),e.format.apply(e,arguments))},e.inherits=r("inherits"),e._extend=function(r,t){if(!t||!x(t))return r;for(var e=Object.keys(t),n=e.length;n--;)r[e[n]]=t[e[n]];return r}}).call(this,r("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":4,_process:3,inherits:2}],6:[function(r,t,e){"use strict";function n(){var r=0,t=h.arrayify(arguments);if(!t.length)return{};var e=h(t).last();return d.isPlainObject(e)&&"__depth"in e&&(r=e.__depth,t.pop()),t.reduce(function(t,e){if("object"!=typeof e)return t;for(var o in e){var i=e[o];d.isObject(i)&&!Array.isArray(i)&&10>r?(t[o]||(t[o]={}),t[o]=n(t[o],i,{__depth:++r})):t[o]=i}return t},{})}function o(r){var t;if("object"!=typeof r||Array.isArray(r)||null===r)return Array.isArray(r)?(t=[],r.forEach(function(r){t.push(o(r))}),t):r;t={};for(var e in r)t[e]=r[e];return t}function i(r,t){var e=!0;for(var n in r)e=e&&t(r[n],n);return e}function u(r,t){for(var e in r)t(r[e],e)}function a(r,t){if(2!==arguments.length)throw Error("expecting two args");if(!d.isObject(r))throw Error("input object must be an object: "+r);if(!d.isObject(t))throw Error("query must be an object: "+t);return Object.keys(t).every(function(e){var n=t[e],o=!1,i=!1;"!"===e.charAt(0)?o=!0:"+"===e.charAt(0)&&(i=!0);var u=r[o||i?e.slice(1):e];return i&&(n=h.arrayify(n),u=h.arrayify(u)),"undefined"==typeof u&&u!==n?o:Array.isArray(n)?f(h.exists(u,n),o):n instanceof RegExp?-1===["boolean","string","number"].indexOf(typeof u)?o:f(n.test(u),o):"function"==typeof n?f(n(u),o):d.isObject(u)&&d.isObject(n)?f(a(u,n),o):f(n===u,o)})}function f(r,t){return t?!r:r}function c(r,t){t=h.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function s(r,t){var e={};if("function"==typeof t)for(var n in r)t(r[n],n)===!0&&(e[n]=r[n]);else if(Array.isArray(t))for(var n in r)t.indexOf(n)>-1&&(e[n]=r[n]);return e}function l(r,t){var e=s(r,t);for(var n in e)delete r[n];return e}function y(r,t){return t.reduce(function(t,e){return t[e]=r[e],t},{})}function p(r,t){return t.trim().split(".").reduce(function(r,t){return r&&r[t]},r)}var h=r("array-tools"),d=r("typical");e.extend=n,e.clone=o,e.every=i,e.each=u,e.exists=a,e.without=c,e.extract=l,e.where=s,e.select=y,e.get=p},{"array-tools":7,typical:11}],7:[function(r,t,e){arguments[4][1][0].apply(e,arguments)},{dup:1,"object-tools":8,typical:11}],8:[function(r,t,e){"use strict";function n(){var r=0,t=h.arrayify(arguments);if(!t.length)return{};var e=h(t).last();return d.isPlainObject(e)&&"__depth"in e&&(r=e.__depth,t.pop()),t.reduce(function(t,e){if("object"!=typeof e)return t;for(var o in e){var i=e[o];d.isObject(i)&&!Array.isArray(i)&&10>r?(t[o]||(t[o]={}),t[o]=n(t[o],i,{__depth:++r})):t[o]=i}return t},{})}function o(r){var t;if("object"!=typeof r||Array.isArray(r)||null===r)return Array.isArray(r)?(t=[],r.forEach(function(r){t.push(o(r))}),t):r;t={};for(var e in r)t[e]=r[e];return t}function i(r,t){var e=!0;for(var n in r)e=e&&t(r[n],n);return e}function u(r,t){for(var e in r)t(r[e],e)}function a(r,t){if(2!==arguments.length)throw Error("expecting two args");if(!d.isObject(r))throw Error("input object must be an object: "+r);if(!d.isObject(t))throw Error("query must be an object: "+t);return Object.keys(t).every(function(e){var n=t[e],o=!1,i=!1;"!"===e.charAt(0)?o=!0:"+"===e.charAt(0)&&(i=!0);var u=r[o||i?e.slice(1):e];return i&&(n=h.arrayify(n),u=h.arrayify(u)),"undefined"==typeof u&&u!==n?o:Array.isArray(n)?f(h.exists(u,n),o):n instanceof RegExp?-1===["boolean","string","number"].indexOf(typeof u)?o:f(n.test(u),o):"function"==typeof n?f(n(u),o):d.isObject(u)&&d.isObject(n)?f(a(u,n),o):f(n===u,o)})}function f(r,t){return t?!r:r}function c(r,t){t=h.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function s(r,t){var e={};if("function"==typeof t)for(var n in r)t(r[n],n)===!0&&(e[n]=r[n]);else if(Array.isArray(t))for(var n in r)t.indexOf(n)>-1&&(e[n]=r[n]);return e}function l(r,t){var e=s(r,t);for(var n in e)delete r[n];return e}function y(r,t){return t.reduce(function(t,e){return t[e]=r[e],t},{})}function p(r,t){return t.trim().split(".").reduce(function(r,t){return r&&r[t]},r)}{var h=r("array-tools"),d=r("typical");r("util")}e.extend=n,e.clone=o,e.every=i,e.each=u,e.exists=a,e.without=c,e.extract=l,e.where=s,e.select=y,e.get=p},{"array-tools":9,typical:11,util:5}],9:[function(require,module,exports){"use strict";function ArrayTools(r){return this instanceof ArrayTools?void(this._data=r):new ArrayTools(r)}function arrayify(r){return null===r||void 0===r?[]:t.isArrayLike(r)?Array.prototype.slice.call(r):Array.isArray(r)?r:[r]}function where(r,t){return arrayify(r).filter(function(r){return o.exists(r,t)})}function pluck(arrayOfObjects,property,property2,property3){if(!Array.isArray(arrayOfObjects))throw new Error(".pluck() input must be an array");return arrayOfObjects.filter(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three}).map(function(obj){var one=eval("obj."+property),two=eval("obj."+property2),three=eval("obj."+property3);return one||two||three})}function pick(){var r=arrayify(arguments),t=r.shift(),e=r;if(!Array.isArray(t))throw new Error(".pick() input must be an array");return t.filter(function(r){return e.some(function(t){return void 0!==r[t]})}).map(function(r){var t={};return e.forEach(function(e){void 0!==r[e]&&(t[e]=r[e])}),t})}function exists(r,e){if(t.isPlainObject(e)){for(var n,i=e,u=!1,a=0;!u&&(n=r[a++]);)u=o.exists(n,i);return u}return r.indexOf(e)>-1}function findWhere(r,t){var e=where(r,t);return e.length?e[0]:null}function without(r,t){return t=arrayify(t),r.filter(function(r){return!exists(t,r)})}function union(r,t,e){var n=o.clone(r);return t.forEach(function(r){if(e){var t={};t[e]=r[e],findWhere(n,t)||n.push(r)}else exists(n,r)||n.push(r)}),n}function commonSequence(r,t){for(var e=[],n=0;n<Math.min(r.length,t.length)&&r[n]===t[n];n++)e.push(r[n]);return e}function unique(r){return r.reduce(function(r,t){return-1===r.indexOf(t)&&r.push(t),r},[])}function spliceWhile(r,t,e){for(var n=0;n<r.length&&e.test(r[n]);n++);var o=[t,n];return o=o.concat(arrayify(arguments).slice(3)),r.splice.apply(r,o)}function extract(r,e){var n=[],i=[];arrayify(r).forEach(function(r,u){t.isPlainObject(e)?o.exists(r,e)&&(n.push(r),i.push(u)):e(r)&&(n.push(r),i.push(u))});for(var u=0;u<i.length;u++)r.splice(i[u]-u,1);return n}function flatten(r){return arrayify(r).reduce(function(r,t){return r.concat(t)},[])}function sortBy(r,t,e){return r.sort(sortByFunc(arrayify(t),e))}function sortByFunc(r,t){var e=r.slice(0),n=e.shift();return function o(i,u){var a,f=i[n],c=u[n];return a="undefined"==typeof f&&"undefined"!=typeof c?-1:"undefined"!=typeof f&&"undefined"==typeof c?1:"undefined"==typeof f&&"undefined"==typeof c?0:t&&t[n]?t[n].indexOf(f)-t[n].indexOf(c):c>f?-1:f>c?1:0,0===a?e.length?(n=e.shift(),o(i,u)):0:(e=r.slice(0),n=e.shift(),a)}}function last(r){return r[r.length-1]}function remove(r,t){return r.splice(r.indexOf(t),1)[0]}function contains(r,t){return r.indexOf(t)>-1}module.exports=ArrayTools;var t=require("typical"),o=require("object-tools"),util=require("util");ArrayTools.pluck=pluck,ArrayTools.pick=pick,ArrayTools.commonSequence=commonSequence,ArrayTools.arrayify=arrayify,ArrayTools.exists=exists,ArrayTools.without=without,ArrayTools.union=union,ArrayTools.where=where,ArrayTools.findWhere=findWhere,ArrayTools.unique=unique,ArrayTools.spliceWhile=spliceWhile,ArrayTools.extract=extract,ArrayTools.flatten=flatten,ArrayTools.sortBy=sortBy,ArrayTools.last=last,ArrayTools.remove=remove,ArrayTools.contains=contains,ArrayTools.prototype.val=function(){return this._data},["filter","reverse","sort","concat","slice","every","some","map"].forEach(function(r){ArrayTools.prototype[r]=function(){return this._data=Array.prototype[r].apply(this._data,arguments),this}}),["join"].forEach(function(r){ArrayTools.prototype[r]=function(){return Array.prototype[r].apply(this._data,arguments)}}),["pluck","pick","arrayify","where","without","unique","spliceWhile","extract","flatten","sortBy"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),this._data=ArrayTools[r].apply(null,t),this}}),["exists","findWhere","last","remove","contains"].forEach(function(r){ArrayTools.prototype[r]=function(){var t=arrayify(arguments);return t.unshift(this._data),ArrayTools[r].apply(null,t)}})},{"object-tools":10,typical:11,util:5}],10:[function(r,t,e){"use strict";function n(){var r=0,t=d.arrayify(arguments);if(!t.length)return{};var e=d(t).last();return v.isPlainObject(e)&&"__depth"in e&&(r=e.__depth,t.pop()),t.reduce(function(t,e){if("object"!=typeof e)return t;for(var o in e){var i=e[o];v.isObject(i)&&!Array.isArray(i)&&10>r?(t[o]||(t[o]={}),t[o]=n(t[o],i,{__depth:++r})):t[o]=i}return t},{})}function o(r){var t;if("object"!=typeof r||Array.isArray(r)||null===r)return Array.isArray(r)?(t=[],r.forEach(function(r){t.push(o(r))}),t):r;t={};for(var e in r)t[e]=r[e];return t}function i(r,t){t=d.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function u(r,t){var e=!0;for(var n in r)e=e&&t(r[n],n);return e}function a(r,t){for(var e in r)t(r[e],e)}function f(r,t){if(2!==arguments.length)throw Error("expecting two args");if("object"!=typeof t)throw Error("query must be an object");r=r||{};var e,n,o=!0;for(var i in t){var u=!1,a=!1;"!"===i.charAt(0)?u=!0:"+"===i.charAt(0)&&(a=!0);var e=t[i],n=r[u||a?i.slice(1):i];if(a&&(e=d.arrayify(e),n=d.arrayify(n)),Array.isArray(e)?(n=n||[],o=e.every(function(r,t){return f(n[t],r)})):o=e instanceof RegExp?"boolean"!=typeof n&&"string"!=typeof n&&"number"!=typeof n?u:u?!e.test(n):e.test(n):"function"==typeof e?u?!e(n):e(n):v.isObject(n)&&v.isObject(e)?f(n,e):u?e!==n:e===n,!o)break}return o}function c(r,t){t=d.arrayify(t);var e=o(r);return t.forEach(function(r){delete e[r]}),e}function s(r){var t={};for(var e in r)void 0!==r[e]&&(t[e]=r[e]);return t}function l(r,t){var e={};if("function"==typeof t)for(var n in r)t(r[n],n)===!0&&(e[n]=r[n]);else if(Array.isArray(t))for(var n in r)t.indexOf(n)>-1&&(e[n]=r[n]);return e}function y(r,t){var e=l(r,t);for(var n in e)delete r[n];return e}function p(r,t){return t.reduce(function(t,e){return t[e]=r[e],t},{})}function h(r,t){return t.trim().split(".").reduce(function(r,t){return r&&r[t]},r)}{var d=r("array-tools"),v=r("typical");r("util")}e.extend=n,e.clone=o,e.defined=s,e.every=u,e.each=a,e.omit=i,e.exists=f,e.without=c,e.extract=y,e.where=l,e.select=p,e.get=h},{"array-tools":9,typical:11,util:5}],11:[function(r,t,e){"use strict";function n(r){return!isNaN(parseFloat(r))&&isFinite(r)}function o(r){return null!==r&&"object"==typeof r&&r.constructor===Object}function i(r){return u(r)&&"number"==typeof r.length}function u(r){return"object"==typeof r&&null!==r}e.isNumber=n,e.isPlainObject=o,e.isArrayLike=i,e.isObject=u},{}],12:[function(r,t,e){arguments[4][11][0].apply(e,arguments)},{dup:11}]},{},[1])(1)}); |
@@ -33,3 +33,3 @@ "use strict"; | ||
if (!(this instanceof ArrayTools)) return new ArrayTools(input); | ||
this._data = input; | ||
this._data = arrayify(input); | ||
} | ||
@@ -42,3 +42,3 @@ | ||
/* Array methods which return the chainable */ | ||
["filter", "reverse", "sort", "concat", "slice", "every", "some", "map"].forEach(function(method){ | ||
["filter", "reverse", "sort", "concat", "slice", "map"].forEach(function(method){ | ||
ArrayTools.prototype[method] = function(){ | ||
@@ -50,4 +50,4 @@ this._data = Array.prototype[method].apply(this._data, arguments); | ||
/* Array method chain terminators, return a scalar */ | ||
["join"].forEach(function(method){ | ||
/* Array method chain terminators, return a scalar or undefined */ | ||
["join", "every", "some", "forEach"].forEach(function(method){ | ||
ArrayTools.prototype[method] = function(){ | ||
@@ -118,6 +118,6 @@ return Array.prototype[method].apply(this._data, arguments); | ||
/** | ||
Query an array, at any depth.. | ||
Deep query an array. | ||
@param {object[]} - the array to query | ||
@param {query} - the query definition | ||
@param {any | any[]} - one or more queries | ||
@returns {Array} | ||
@@ -142,3 +142,3 @@ @category chainable | ||
All query expressions can be negated (where NOT the value). Prefix the property name with `!`: | ||
or where NOT the value (prefix the property name with `!`) | ||
```js | ||
@@ -164,3 +164,3 @@ > a.where(data, { "!age": 10 }) | ||
You can query to any arbitrary depth. So with deeper data, like: | ||
You can query to any arbitrary depth. So with deeper data, like this: | ||
```js | ||
@@ -174,3 +174,3 @@ > deepData = [ | ||
return records containing `favourite.colour` values matching the regex `/red/` | ||
get records with `favourite.colour` values matching `/red/` | ||
```js | ||
@@ -181,4 +181,4 @@ > a.where(deepData, { favourite: { colour: /red/ } }) | ||
``` | ||
Prefix the property name with `+` if the value you want to match could be singular _or_ a member of an array. | ||
if the value you're looking for _maybe_ part of an array, prefix the property name with `+`. Now Zhana is included: | ||
```js | ||
@@ -191,2 +191,11 @@ > a.where(deepData, { favourite: { "+colour": /red/ } }) | ||
you can combine any of the above by supplying an array of queries. Records will be returned if _any_ of the queries match: | ||
```js | ||
> var nameBeginsWithY = { name: /^Y/ }; | ||
> var faveColourIncludesWhite = { favourite: { "+colour": "white" } }; | ||
> a.where(deepData, [ nameBeginsWithY, faveColourIncludesWhite ]) | ||
[ { name: 'Yana', favourite: { colour: 'dark red' } }, | ||
{ name: 'Zhana', favourite: { colour: [ "white", "red" ] } } ] | ||
``` | ||
*/ | ||
@@ -201,6 +210,6 @@ function where(array, query){ | ||
/** | ||
Returns a new array with the same content as the input minus the specified values. | ||
Returns a new array with the same content as the input minus the specified values. It accepts the same query syntax as {@link module:array-tools.where}. | ||
@param {Array} - the input array | ||
@param {*} - a single, or array of values to omit | ||
@param {any | any[]} - one, or more queries | ||
@returns {Array} | ||
@@ -214,2 +223,11 @@ @category chainable | ||
[ 1 ] | ||
> data = [ | ||
{ name: "Dana", age: 30 }, | ||
{ name: "Yana", age: 20 }, | ||
{ name: "Zhana", age: 10 } | ||
] | ||
> a.without(data, { name: /ana/ }) | ||
[] | ||
@alias module:array-tools.without | ||
@@ -224,2 +242,6 @@ */ | ||
/** | ||
@private | ||
@returns boolean | ||
*/ | ||
function testValue(value, test){ | ||
@@ -272,6 +294,6 @@ if (t.isPlainObject(test)){ | ||
/** | ||
Plucks the value of the specified property from each object in the input array | ||
Returns an array containing the value of each specified property, if it exists. | ||
@param recordset {object[]} - The input recordset | ||
@param property {...string} - Up to three property names - the first one found will be returned. | ||
@param property {string} - Property name | ||
@returns {Array} | ||
@@ -293,17 +315,20 @@ @category chainable | ||
*/ | ||
function pluck(recordset, property, property2, property3){ | ||
function pluck(recordset, property){ | ||
if (!Array.isArray(recordset)) throw new Error(".pluck() input must be an array"); | ||
var properties = arrayify(property); | ||
return recordset | ||
.filter(function(obj){ | ||
var one = eval("obj." + property); | ||
var two = eval("obj." + property2); | ||
var three = eval("obj." + property3); | ||
return one || two || three; | ||
.map(function(item){ | ||
var property = properties.reduce(function(prev, prop){ | ||
if (prev){ | ||
return prev; | ||
} else { | ||
if (typeof o.get(item, prop) !== "undefined") return prop; | ||
} | ||
}, ""); | ||
// console.log(property); | ||
return o.get(item, property); | ||
}) | ||
.map(function(obj){ | ||
var one = eval("obj." + property); | ||
var two = eval("obj." + property2); | ||
var three = eval("obj." + property3); | ||
return one || two || three; | ||
.filter(function(item){ | ||
return typeof item !== "undefined"; | ||
}); | ||
@@ -376,4 +401,3 @@ } | ||
function findWhere(recordset, query){ | ||
var result = where(recordset, query); | ||
return result.length ? result[0] : null; | ||
return where(recordset, query)[0]; | ||
} | ||
@@ -380,0 +404,0 @@ |
{ | ||
"name": "array-tools", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "2.0.0-1", | ||
"version": "2.0.0-2", | ||
"description": "Lightweight, use-anywhere toolkit for working with array data. 1.5k, compressed.", | ||
@@ -43,6 +43,7 @@ "repository": "https://github.com/75lb/array-tools.git", | ||
"dependencies": { | ||
"ansi-escape-sequences": "^2.0.0", | ||
"object-tools": "^2.0.0-0", | ||
"typical": "^2.1", | ||
"transform-tools": "~0.0" | ||
"transform-tools": "~0.1", | ||
"typical": "^2.1" | ||
} | ||
} |
@@ -7,14 +7,24 @@ [![view on npm](http://img.shields.io/npm/v/array-tools.svg)](https://www.npmjs.org/package/array-tools) | ||
***this documentation is for the pre-release version*** | ||
# array-tools | ||
Lightweight, use-anywhere toolkit for working with array data. | ||
```js | ||
> var a = require("array-tools"); | ||
There are four ways to use it. | ||
1) As a command-line tool. E.g. array-tools downloads last month: | ||
```sh | ||
$ curl -s https://api.npmjs.org/downloads/range/last-month/array-tools \ | ||
| object-tools get downloads \ | ||
| array-tools pluck downloads \ | ||
| array-tools join "," \ | ||
| spark | ||
▂▅▃▅▅▁▁▃▄▃▆▂▂▁▁▂▄▃▃▁▁▂█▆▆▄▁▃▅▃ | ||
``` | ||
There are four ways to use it. | ||
2) As a standard library, passing the input array on each method invocation: | ||
1) As a standard library, passing the input array on each method invocation: | ||
```js | ||
> var a = require("array-tools"); | ||
```js | ||
> var remainder = a.without([ 1, 2, 3, 4, 5 ], 1) | ||
@@ -25,3 +35,3 @@ > a.exists(remainder, 1) | ||
2) As a chainable method, passing the input array once then chaining from there: | ||
3) As a chainable method, passing the input array once then chaining from there: | ||
@@ -33,3 +43,3 @@ ```js | ||
3) As a base class. | ||
4) As a base class. | ||
```js | ||
@@ -54,19 +64,2 @@ var util = require("util"); | ||
4) As a command-line tool. | ||
```sh | ||
$ curl -s "https://api.github.com/users/75lb/repos?page=1&per_page=100" | array-tools pick full_name description | ||
[ | ||
{ | ||
"full_name": "75lb/ansi-escape-sequences", | ||
"description": "A simple library containing all known terminal ansi escape codes and sequences." | ||
}, | ||
{ | ||
"full_name": "75lb/baldrick", | ||
"description": "Your own private dogsbody. Does the shitty work you can't be arsed to do." | ||
}, | ||
etc, | ||
etc | ||
] | ||
``` | ||
#### More on chaining | ||
@@ -118,3 +111,3 @@ * Each method returning an `Array` (e.g. `where`, `without`) can be chained. | ||
* [.without(array, toRemove)](#module_array-tools.without) ⇒ <code>Array</code> | ||
* [.pluck(recordset, ...property)](#module_array-tools.pluck) ⇒ <code>Array</code> | ||
* [.pluck(recordset, property)](#module_array-tools.pluck) ⇒ <code>Array</code> | ||
* [.pick(recordset, ...property)](#module_array-tools.pick) ⇒ <code>Array.<object></code> | ||
@@ -171,3 +164,3 @@ * [.union(array1, array2, idKey)](#module_array-tools.union) ⇒ <code>Array</code> | ||
### a.where(array, query) ⇒ <code>Array</code> | ||
Query an array, at any depth.. | ||
Deep query an array. | ||
@@ -180,3 +173,3 @@ **Kind**: static method of <code>[array-tools](#module_array-tools)</code> | ||
| array | <code>Array.<object></code> | the array to query | | ||
| query | <code>query</code> | the query definition | | ||
| query | <code>any</code> | <code>Array.<any></code> | one or more queries | | ||
@@ -199,3 +192,3 @@ **Example** | ||
All query expressions can be negated (where NOT the value). Prefix the property name with `!`: | ||
or where NOT the value (prefix the property name with `!`) | ||
```js | ||
@@ -221,3 +214,3 @@ > a.where(data, { "!age": 10 }) | ||
You can query to any arbitrary depth. So with deeper data, like: | ||
You can query to any arbitrary depth. So with deeper data, like this: | ||
```js | ||
@@ -231,3 +224,3 @@ > deepData = [ | ||
return records containing `favourite.colour` values matching the regex `/red/` | ||
get records with `favourite.colour` values matching `/red/` | ||
```js | ||
@@ -238,4 +231,4 @@ > a.where(deepData, { favourite: { colour: /red/ } }) | ||
``` | ||
Prefix the property name with `+` if the value you want to match could be singular _or_ a member of an array. | ||
if the value you're looking for _maybe_ part of an array, prefix the property name with `+`. Now Zhana is included: | ||
```js | ||
@@ -247,5 +240,15 @@ > a.where(deepData, { favourite: { "+colour": /red/ } }) | ||
``` | ||
you can combine any of the above by supplying an array of queries. Records will be returned if _any_ of the queries match: | ||
```js | ||
> var nameBeginsWithY = { name: /^Y/ }; | ||
> var faveColourIncludesWhite = { favourite: { "+colour": "white" } }; | ||
> a.where(deepData, [ nameBeginsWithY, faveColourIncludesWhite ]) | ||
[ { name: 'Yana', favourite: { colour: 'dark red' } }, | ||
{ name: 'Zhana', favourite: { colour: [ "white", "red" ] } } ] | ||
``` | ||
<a name="module_array-tools.without"></a> | ||
### a.without(array, toRemove) ⇒ <code>Array</code> | ||
Returns a new array with the same content as the input minus the specified values. | ||
Returns a new array with the same content as the input minus the specified values. It accepts the same query syntax as [where](#module_array-tools.where). | ||
@@ -258,3 +261,3 @@ **Kind**: static method of <code>[array-tools](#module_array-tools)</code> | ||
| array | <code>Array</code> | the input array | | ||
| toRemove | <code>\*</code> | a single, or array of values to omit | | ||
| toRemove | <code>any</code> | <code>Array.<any></code> | one, or more queries | | ||
@@ -268,6 +271,14 @@ **Example** | ||
[ 1 ] | ||
> data = [ | ||
{ name: "Dana", age: 30 }, | ||
{ name: "Yana", age: 20 }, | ||
{ name: "Zhana", age: 10 } | ||
] | ||
> a.without(data, { name: /ana/ }) | ||
[] | ||
``` | ||
<a name="module_array-tools.pluck"></a> | ||
### a.pluck(recordset, ...property) ⇒ <code>Array</code> | ||
Plucks the value of the specified property from each object in the input array | ||
### a.pluck(recordset, property) ⇒ <code>Array</code> | ||
Returns an array containing the value of each specified property, if it exists. | ||
@@ -280,3 +291,3 @@ **Kind**: static method of <code>[array-tools](#module_array-tools)</code> | ||
| recordset | <code>Array.<object></code> | The input recordset | | ||
| ...property | <code>string</code> | Up to three property names - the first one found will be returned. | | ||
| property | <code>string</code> | Property name | | ||
@@ -283,0 +294,0 @@ **Example** |
@@ -6,2 +6,20 @@ var test = require("tape"); | ||
var f = { | ||
recordset: [ | ||
{one: 1, two: 2}, | ||
{one: 1, two: 3}, | ||
{one: 2, two: 5}, | ||
{two: "two"}, | ||
{one: "one", two: "zwei"}, | ||
] | ||
}; | ||
test("chaining: correct methods return the chainable", function(t){ | ||
function func(i){return false;} | ||
t.notOk(a(f.recordset).some(func) instanceof a); | ||
t.notOk(a(f.recordset).every(func) instanceof a); | ||
t.notOk(a(f.recordset).join() instanceof a); | ||
t.end(); | ||
}); | ||
test("chaining: .pluck", function(t){ | ||
@@ -97,1 +115,2 @@ var data = [ | ||
}); | ||
var test = require("tape"); | ||
var a = require("../"); | ||
test(".pluck", function(t){ | ||
var data = [ | ||
{one: 1, two: 2}, | ||
{two: "two"}, | ||
{one: "one", two: "zwei"}, | ||
]; | ||
t.deepEqual(a.pluck(data, "one"), [ 1, "one" ]); | ||
t.deepEqual(a.pluck(data, "two"), [ 2, "two", "zwei" ]); | ||
t.deepEqual(a.pluck(data, "one", "two"), [ 1, "two", "one" ]); | ||
var fixture = [ | ||
{one: 1, two: 2}, | ||
{two: "two"}, | ||
{one: "one", two: "zwei"}, | ||
{deep: { a: "yep" }}, | ||
{deep: { a: "again" }}, | ||
{deep: "not here" }, | ||
{deep: { b: "or here" }} | ||
]; | ||
test(".pluck(array, property)", function(t){ | ||
t.deepEqual(a.pluck(fixture, "one"), [ 1, "one" ]); | ||
t.deepEqual(a.pluck(fixture, "two"), [ 2, "two", "zwei" ]); | ||
t.end(); | ||
}); | ||
test(".pluck expression (e.g. \"item.prop\")", function(t){ | ||
var data = [ | ||
{one: { inside: "yep" }}, | ||
{one: { inside: "again" }}, | ||
{one: "not here" }, | ||
{one: { or: "or here" }} | ||
]; | ||
t.deepEqual(a.pluck(data, "one.inside"), [ "yep", "again" ]); | ||
test(".pluck(array, [property])", function(t){ | ||
t.deepEqual(a.pluck(fixture, [ "one", "two" ]), [ 1, "two", "one" ]); | ||
t.end(); | ||
}); | ||
test(".pluck(array, property.property)", function(t){ | ||
t.deepEqual(a.pluck(fixture, "deep.a"), [ "yep", "again" ]); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
575
25
174288
4
4195
+ Addedansi-escape-sequences@^2.0.0
+ Addedansi-escape-sequences@2.2.2(transitive)
+ Addedcollect-all@0.2.1(transitive)
+ Addedstream-via@0.1.1(transitive)
Updatedtransform-tools@~0.1