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

datafield

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datafield - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

.github/ISSUE_TEMPLATE/bug_report.md

2

dist/datafield.min.js

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.DataField=e()}(this,function(){"use strict";function t(t,e){return t.hasOwnProperty(e)?t[e]:function(t,e,r){if(!t||"object"!=typeof t)return"function"==typeof r?r():r;if(!e)return t;var n=Object.assign({},t);e=e.split(".");for(var i=0;i<e.length;i++){if(!n.hasOwnProperty(e[i]))return"function"==typeof r?r():r;if((n=n[e[i]])!==Object(n)&&i<e.length-1)return"function"==typeof r?r():r}return n}(t,e)}function e(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i>n}function r(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i>=n}function n(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i<n}function i(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i<=n}function s(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),n instanceof Date?i.getTime()===n.getTime():i===n}function a(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),n instanceof Date?i.getTime()!==n.getTime():i!==n}function o(e,r){return Boolean(t(e,r))}function c(t){switch(t){case"NO_CONS":throw new Error("array should be passed into the DataField constructor");case"NOT_ARRAY":throw new Error("DataField can only accept arrays");case"RANGE_ARG":throw new Error("DataField range() method accepts 2 arguments of the same type");case"NO_SEL":throw new Error("DataField selector not specified, use .where(selector)");case"NO_SEL_OR_VAL":throw new Error("DataField selector or value not specified, use .where(selector) and check method arguments");case"NO_MATH_SEL":throw new Error("DataField selector should be passed as an argument when using math methods");default:throw new Error("DataField error")}}var u=function(t,e){void 0===t&&(t=c("NO_CONS")),Array.isArray(t)||c("NOT_ARRAY"),this.data=t.slice(0),this.caret=0,this.selector=e},h={length:{configurable:!0}};return u.prototype.exists=function(e){void 0===e&&(e=this.selector);var r=this.data.filter(function(r){return void 0!==t(r,e)});return new u(r,this.selector)},u.prototype.has=function(e){var r=this.data.filter(function(r){var n=t(r,e);return Array.isArray(n)?n.length:n});return new u(r,this.selector)},u.prototype.take=function(t){void 0===t&&(t=1);var e=this.data.slice(this.caret,this.caret+t);return this.caret+=t,new u(e,this.selector)},h.length.get=function(){return this.__reset(),this.data.length},u.prototype.takeRandom=function(t){void 0===t&&(t=1),"number"!=typeof t&&(t=parseInt(String(t))),isNaN(t)&&(t=1),(t=Math.floor(t))>this.data.length&&(t=this.data.length);var e=function t(e,r,n){void 0===n&&(n=[]);var i=Math.floor(Math.random()*e);return n.includes(i)||n.push(i),n.length===r?n:t(e,r,n)}(this.data.length,t),r=this.data.filter(function(t,r){return e.includes(r)});return new u(r,this.selector)},u.prototype.where=function(t){return this.selector=t,this},u.prototype.isTruthy=function(){var t=this;this.selector||c("NO_SEL");var e=this.data.filter(function(e){return o(e,t.selector)});return new u(e,this.selector)},u.prototype.isFalsy=function(){var t=this;this.selector||c("NO_SEL");var e=this.data.filter(function(e){return!o(e,t.selector)});return new u(e,this.selector)},u.prototype.eq=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return s(r,e.selector,t)});return new u(r,this.selector)},u.prototype.not=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return a(r,e.selector,t)});return new u(r,this.selector)},u.prototype.gt=function(t){var r=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var n=this.data.filter(function(n){return e(n,r.selector,t)});return new u(n,this.selector)},u.prototype.lt=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return n(r,e.selector,t)});return new u(r,this.selector)},u.prototype.gte=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var n=this.data.filter(function(n){return r(n,e.selector,t)});return new u(n,this.selector)},u.prototype.lte=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return i(r,e.selector,t)});return new u(r,this.selector)},u.prototype.range=function(t,e){var i,s,a,o=this;Array.isArray(t)&&2===t.length&&(i=[t[0],t[1]],t=i[0],e=i[1]),typeof(s=t)==typeof(a=e)&&("object"==typeof s&&s instanceof Date&&a instanceof Date||"number"==typeof s||"string"==typeof s)||c("RANGE_ARG"),this.selector||c("NO_SEL");var h=this.data.filter(function(e){return r(e,o.selector,t)}).filter(function(t){return n(t,o.selector,e)});return new u(h,this.selector)},u.prototype.includes=function(e){var r=this;if(this.selector||c("NO_SEL"),void 0===e)return this;var n=this.data.filter(function(n){var i=t(n,r.selector);return Array.isArray(i)&&i.includes(e)});return new u(n,this.selector)},u.prototype.any=function(t){var e=this;if(void 0===t&&(t={}),"object"!=typeof t||!Object.keys(t).length)return this;var r=this.data.filter(function(r){return e.__checkForAny(r,t)});return new u(r,this.selector)},u.prototype.all=function(t){var e=this;if(void 0===t&&(t={}),"object"!=typeof t||!Object.keys(t).length)return this;var r=this.data.filter(function(r){return e.__checkForAll(r,t)});return new u(r,this.selector)},u.prototype.sort=function(t){void 0===t&&(t={});var e=t.by,r=t.order;void 0===r&&(r="asc");var n=t.type,i=this.__findFirstOccurrence(e);return e&&i?("desc"!==r&&(r="asc"),n||(n=typeof i),this.selector=e,"asc"===r?this.asc(n):this.desc(n)):this},u.prototype.asc=function(e){if(this.selector||c("NO_SEL"),!this.data.length)return this;var r=[];e=e||this.__getType();var n=this.selector;switch(e){case"n":case"num":case"number":r=this.data.slice().sort(function(e,r){return t(e,n)-t(r,n)});break;case"string":case"str":case"s":r=this.data.slice().sort(function(e,r){return String(t(e,n)).localeCompare(String(t(r,n)))});break;case"date":case"d":r=this.data.slice().sort(function(e,r){return Number(new Date(t(e,n)))-Number(new Date(t(r,n)))});break;case"array":case"arr":r=this.data.slice().sort(function(e,r){var i=t(e,n),s=t(r,n);if(Array.isArray(i)&&Array.isArray(s))return i.length-s.length});break;default:return this}return new u(r,this.selector)},u.prototype.desc=function(e){if(this.selector||c("NO_SEL"),!this.data.length)return this;var r=[];e=e||this.__getType();var n=this.selector;switch(e){case"num":case"number":r=this.data.slice().sort(function(e,r){return t(r,n)-t(e,n)});break;case"str":case"string":r=this.data.slice().sort(function(e,r){return String(t(r,n)).localeCompare(String(t(e,n)))});break;case"date":r=this.data.slice().sort(function(e,r){return Number(new Date(t(r,n)))-Number(new Date(t(e,n)))});break;case"arr":case"array":r=this.data.slice().sort(function(e,r){var i=t(e,n),s=t(r,n);if(Array.isArray(i)&&Array.isArray(s))return s.length-i.length});break;default:return this}return new u(r,this.selector)},u.prototype.sum=function(e,r){return void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset(),this.data.reduce(function(n,i){var s=t(i,e);return r?"number"==typeof s?n+s:n:isNaN(s)?n:n+Number(s)},0)},u.prototype.avg=function(e,r){void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset();var n=0,i=0;return this.data.forEach(function(s){var a=t(s,e);r?"number"==typeof a&&(i++,n+=a):isNaN(a)||(i++,n+=Number(a))}),i?n/i:0},u.prototype.median=function(e,r){void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset();var n=[];if(this.data.forEach(function(i){var s=t(i,e);r?"number"==typeof s&&n.push(s):isNaN(s)||n.push(Number(s))}),0===n.length)return 0;if(1===n.length)return n[0];n.sort(function(t,e){return t-e});var i=Math.floor(n.length/2);return n.length%2?n[i]:(n[i-1]+n[i])/2},u.prototype.values=function(){return this.__reset(),this.data.slice(0)},u.prototype.toArray=function(){return this.values()},u.prototype.__reset=function(){this.selector=""},u.prototype.__getType=function(e){if(void 0===e&&(e=this.selector),e)for(var r=0;r<this.data.length;r++){var n=t(this.data[r],e);if(n)return Array.isArray(n)?"array":typeof n}},u.prototype.__findFirstOccurrence=function(e){if(e)for(var r=0;r<this.data.length;r++){var n=t(this.data[r],e);if(n)return n}},u.prototype.__checkForAny=function(t,c){for(var u=0,h=Object.keys(c);u<h.length;u+=1){var f=h[u];switch(f){case"gt":if(e(t,this.selector,c[f]))return!0;break;case"gte":if(r(t,this.selector,c[f]))return!0;break;case"lt":if(n(t,this.selector,c[f]))return!0;break;case"lte":if(i(t,this.selector,c[f]))return!0;break;case"eq":if(s(t,this.selector,c[f]))return!0;break;case"not":if(a(t,this.selector,c[f]))return!0;break;case"is":if(c[f]===o(t,this.selector))return!0;break;case"range":if(Array.isArray(c[f])&&2===c[f].length&&r(t,this.selector,c[f][0])&&n(t,this.selector,c[f][1]))return!0}}},u.prototype.__checkForAll=function(t,c){for(var u=0,h=Object.keys(c);u<h.length;u+=1){var f=h[u];switch(f){case"gt":if(!e(t,this.selector,c[f]))return;break;case"gte":if(!r(t,this.selector,c[f]))return;break;case"lt":if(!n(t,this.selector,c[f]))return;break;case"lte":if(!i(t,this.selector,c[f]))return;break;case"eq":if(!s(t,this.selector,c[f]))return;break;case"not":if(!a(t,this.selector,c[f]))return;break;case"is":if(c[f]!==o(t,this.selector))return;break;case"range":if(Array.isArray(c[f])&&2===c[f].length&&(!r(t,this.selector,c[f][0])||!n(t,this.selector,c[f][1])))return}}return!0},Object.defineProperties(u.prototype,h),u});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.DataField=e()}(this,function(){"use strict";function t(t,e){return t.hasOwnProperty(e)?t[e]:function(t,e,r){if(!t||"object"!=typeof t)return"function"==typeof r?r():r;if(!e)return t;var n=Object.assign({},t);e=e.split(".");for(var i=0;i<e.length;i++){if(!n.hasOwnProperty(e[i]))return"function"==typeof r?r():r;if((n=n[e[i]])!==Object(n)&&i<e.length-1)return"function"==typeof r?r():r}return n}(t,e)}function e(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i>n}function r(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i>=n}function n(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i<n}function i(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),i<=n}function s(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),n instanceof Date?i.getTime()===n.getTime():i===n}function a(e,r,n){var i=t(e,r);return Array.isArray(i)&&(i=i.length),n instanceof Date&&(i=new Date(i)),n instanceof Date?i.getTime()!==n.getTime():i!==n}function o(e,r){return Boolean(t(e,r))}function c(t){switch(t){case"NO_CONS":throw new Error("array should be passed into the DataField constructor");case"NOT_ARRAY":throw new Error("DataField can only accept arrays");case"RANGE_ARG":throw new Error("DataField range() method accepts 2 arguments of the same type");case"NO_SEL":throw new Error("DataField selector not specified, use .where(selector)");case"NO_SEL_OR_VAL":throw new Error("DataField selector or value not specified, use .where(selector) and check method arguments");case"NO_MATH_SEL":throw new Error("DataField selector should be passed as an argument when using math methods");case"NO_STR_VALUE":throw new Error("DataField selector .pick() expects a string");case"BAD_PICK_ARG":throw new Error('DataField selector .pick() should have a proper argument value — "even", "odd" or "{number}n" (i.e. 3n for every third element)');default:throw new Error("DataField error")}}var u=function(t,e){void 0===t&&(t=c("NO_CONS")),Array.isArray(t)||c("NOT_ARRAY"),this.data=t.slice(0),this.selector=e,this.caret=0},h={length:{configurable:!0}};return u.prototype.exists=function(e){void 0===e&&(e=this.selector);var r=this.data.filter(function(r){return void 0!==t(r,e)});return new u(r,this.selector)},u.prototype.has=function(e){var r=this.data.filter(function(r){var n=t(r,e);return Array.isArray(n)?n.length:n});return new u(r,this.selector)},u.prototype.take=function(t){void 0===t&&(t=1);var e=this.data.slice(this.caret,this.caret+t);return this.caret+=t,new u(e,this.selector)},h.length.get=function(){return this.__reset(),this.data.length},u.prototype.takeRandom=function(t){void 0===t&&(t=1),"number"!=typeof t&&(t=parseInt(String(t))),isNaN(t)&&(t=1),(t=Math.floor(t))>this.data.length&&(t=this.data.length);var e=function t(e,r,n){void 0===n&&(n=[]);var i=Math.floor(Math.random()*e);return n.includes(i)||n.push(i),n.length===r?n:t(e,r,n)}(this.data.length,t),r=this.data.filter(function(t,r){return e.includes(r)});return new u(r,this.selector)},u.prototype.where=function(t){return this.selector=t,this},u.prototype.isTruthy=function(){var t=this;this.selector||c("NO_SEL");var e=this.data.filter(function(e){return o(e,t.selector)});return new u(e,this.selector)},u.prototype.isFalsy=function(){var t=this;this.selector||c("NO_SEL");var e=this.data.filter(function(e){return!o(e,t.selector)});return new u(e,this.selector)},u.prototype.eq=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return s(r,e.selector,t)});return new u(r,this.selector)},u.prototype.not=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return a(r,e.selector,t)});return new u(r,this.selector)},u.prototype.gt=function(t){var r=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var n=this.data.filter(function(n){return e(n,r.selector,t)});return new u(n,this.selector)},u.prototype.lt=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return n(r,e.selector,t)});return new u(r,this.selector)},u.prototype.gte=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var n=this.data.filter(function(n){return r(n,e.selector,t)});return new u(n,this.selector)},u.prototype.lte=function(t){var e=this;this.selector&&void 0!==t||c("NO_SEL_OR_VAL");var r=this.data.filter(function(r){return i(r,e.selector,t)});return new u(r,this.selector)},u.prototype.range=function(t,e){var i,s,a,o=this;Array.isArray(t)&&2===t.length&&(i=[t[0],t[1]],t=i[0],e=i[1]),typeof(s=t)==typeof(a=e)&&("object"==typeof s&&s instanceof Date&&a instanceof Date||"number"==typeof s||"string"==typeof s)||c("RANGE_ARG"),this.selector||c("NO_SEL");var h=this.data.filter(function(e){return r(e,o.selector,t)}).filter(function(t){return n(t,o.selector,e)});return new u(h,this.selector)},u.prototype.includes=function(e){var r=this;if(this.selector||c("NO_SEL"),void 0===e)return this;var n=this.data.filter(function(n){var i=t(n,r.selector);return Array.isArray(i)&&i.includes(e)});return new u(n,this.selector)},u.prototype.any=function(t){var e=this;if(void 0===t&&(t={}),"object"!=typeof t||!Object.keys(t).length)return this;var r=this.data.filter(function(r){return e.__checkForAny(r,t)});return new u(r,this.selector)},u.prototype.all=function(t){var e=this;if(void 0===t&&(t={}),"object"!=typeof t||!Object.keys(t).length)return this;var r=this.data.filter(function(r){return e.__checkForAll(r,t)});return new u(r,this.selector)},u.prototype.pick=function(t){if(!t)return this;if("string"!=typeof t&&c("NO_STR_VALUE"),"even"===(t=t.toLowerCase()))return new u(this.data.filter(function(t,e){return!(e%2)}));if("odd"===t)return new u(this.data.filter(function(t,e){return e%2}));if("n"===t.slice(-1)&&Number(t.slice(0,-1))){var e=Number(t.slice(0,-1));return new u(this.data.filter(function(t,r){return!(r%e)}))}c("BAD_PICK_ARG")},u.prototype.sort=function(t){void 0===t&&(t={});var e=t.by,r=t.order;void 0===r&&(r="asc");var n=t.type,i=this.__findFirstOccurrence(e);return e&&i?("desc"!==r&&(r="asc"),n||(n=typeof i),this.selector=e,"asc"===r?this.asc(n):this.desc(n)):this},u.prototype.asc=function(e){if(this.selector||c("NO_SEL"),!this.data.length)return this;var r=[];e=e||this.__getType();var n=this.selector;switch(e){case"n":case"num":case"number":r=this.data.slice().sort(function(e,r){return t(e,n)-t(r,n)});break;case"string":case"str":case"s":r=this.data.slice().sort(function(e,r){return String(t(e,n)).localeCompare(String(t(r,n)))});break;case"date":case"d":r=this.data.slice().sort(function(e,r){return Number(new Date(t(e,n)))-Number(new Date(t(r,n)))});break;case"array":case"arr":r=this.data.slice().sort(function(e,r){var i=t(e,n),s=t(r,n);if(Array.isArray(i)&&Array.isArray(s))return i.length-s.length});break;default:return this}return new u(r,this.selector)},u.prototype.desc=function(e){if(this.selector||c("NO_SEL"),!this.data.length)return this;var r=[];e=e||this.__getType();var n=this.selector;switch(e){case"num":case"number":r=this.data.slice().sort(function(e,r){return t(r,n)-t(e,n)});break;case"str":case"string":r=this.data.slice().sort(function(e,r){return String(t(r,n)).localeCompare(String(t(e,n)))});break;case"date":r=this.data.slice().sort(function(e,r){return Number(new Date(t(r,n)))-Number(new Date(t(e,n)))});break;case"arr":case"array":r=this.data.slice().sort(function(e,r){var i=t(e,n),s=t(r,n);if(Array.isArray(i)&&Array.isArray(s))return s.length-i.length});break;default:return this}return new u(r,this.selector)},u.prototype.sum=function(e,r){return void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset(),this.data.reduce(function(n,i){var s=t(i,e);return r?"number"==typeof s?n+s:n:isNaN(s)?n:n+Number(s)},0)},u.prototype.avg=function(e,r){void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset();var n=0,i=0;return this.data.forEach(function(s){var a=t(s,e);r?"number"==typeof a&&(i++,n+=a):isNaN(a)||(i++,n+=Number(a))}),i?n/i:0},u.prototype.median=function(e,r){void 0===e&&(e=c("NO_MATH_SEL")),void 0===r&&(r=!0),this.__reset();var n=[];if(this.data.forEach(function(i){var s=t(i,e);r?"number"==typeof s&&n.push(s):isNaN(s)||n.push(Number(s))}),0===n.length)return 0;if(1===n.length)return n[0];n.sort(function(t,e){return t-e});var i=Math.floor(n.length/2);return n.length%2?n[i]:(n[i-1]+n[i])/2},u.prototype.values=function(){return this.__reset(),this.data.slice(0)},u.prototype.toArray=function(){return this.values()},u.prototype.__reset=function(){this.selector=""},u.prototype.__getType=function(e){if(void 0===e&&(e=this.selector),e)for(var r=0;r<this.data.length;r++){var n=t(this.data[r],e);if(n)return Array.isArray(n)?"array":typeof n}},u.prototype.__findFirstOccurrence=function(e){if(e)for(var r=0;r<this.data.length;r++){var n=t(this.data[r],e);if(n)return n}},u.prototype.__checkForAny=function(t,c){for(var u=0,h=Object.keys(c);u<h.length;u+=1){var f=h[u];switch(f){case"gt":if(e(t,this.selector,c[f]))return!0;break;case"gte":if(r(t,this.selector,c[f]))return!0;break;case"lt":if(n(t,this.selector,c[f]))return!0;break;case"lte":if(i(t,this.selector,c[f]))return!0;break;case"eq":if(s(t,this.selector,c[f]))return!0;break;case"not":if(a(t,this.selector,c[f]))return!0;break;case"is":if(c[f]===o(t,this.selector))return!0;break;case"range":if(Array.isArray(c[f])&&2===c[f].length&&r(t,this.selector,c[f][0])&&n(t,this.selector,c[f][1]))return!0}}},u.prototype.__checkForAll=function(t,c){for(var u=0,h=Object.keys(c);u<h.length;u+=1){var f=h[u];switch(f){case"gt":if(!e(t,this.selector,c[f]))return;break;case"gte":if(!r(t,this.selector,c[f]))return;break;case"lt":if(!n(t,this.selector,c[f]))return;break;case"lte":if(!i(t,this.selector,c[f]))return;break;case"eq":if(!s(t,this.selector,c[f]))return;break;case"not":if(!a(t,this.selector,c[f]))return;break;case"is":if(c[f]!==o(t,this.selector))return;break;case"range":if(Array.isArray(c[f])&&2===c[f].length&&(!r(t,this.selector,c[f][0])||!n(t,this.selector,c[f][1])))return}}return!0},Object.defineProperties(u.prototype,h),u});
//# sourceMappingURL=datafield.min.js.map

@@ -13,4 +13,4 @@ {

"repository": {
"type" : "git",
"url" : "https://github.com/tomkallen/datafield.git"
"type": "git",
"url": "https://github.com/tomkallen/datafield.git"
},

@@ -21,3 +21,3 @@ "bugs": {

},
"version": "0.2.2",
"version": "0.3.0",
"description": "Sort, select, filter, evaluate and perform maths on your arrays of data",

@@ -46,15 +46,21 @@ "main": "./dist/datafield.min.js",

},
"standard": {
"parser": "babel-eslint"
},
"author": "Alex Bykov",
"license": "MIT",
"devDependencies": {
"babel-cli": "6.26.0",
"babel-eslint": "10.0.1",
"babel-preset-env": "1.7.0",
"codecov": "3.0.4",
"husky": "1.0.0-rc.13",
"jest": "23.5.0",
"babel-preset-flow": "6.23.0",
"codecov": "3.1.0",
"husky": "1.1.4",
"jest": "23.6.0",
"rimraf": "2.6.2",
"rollup": "0.65.0",
"rollup-plugin-buble": "0.19.2",
"rollup-plugin-commonjs": "9.1.6",
"rollup-plugin-node-resolve": "3.3.0",
"rollup-plugin-terser": "2.0.1",
"rollup": "0.67.1",
"rollup-plugin-buble": "0.19.4",
"rollup-plugin-commonjs": "9.2.0",
"rollup-plugin-node-resolve": "3.4.0",
"rollup-plugin-terser": "3.0.0",
"snazzy": "8.0.0",

@@ -61,0 +67,0 @@ "standard": "12.0.1"

@@ -6,3 +6,3 @@ <p align="center">

<h3 align="center">Sort, select, filter and perform maths and analysis on your arrays of data</h3>
<h4 color="blue" align="center">:koala: version 0.2.2 is out</h4>
<h4 color="blue" align="center">:bear: version 0.3.0 is out</h4>

@@ -9,0 +9,0 @@ [![codecov](https://codecov.io/gh/tomkallen/datafield/branch/master/graph/badge.svg)](https://codecov.io/gh/tomkallen/datafield)

@@ -1,3 +0,15 @@

import { findProp, randomTakes, checkTypes } from './utils'
import { isGreater, isLess, isLessOrEq, isGreaterOrEq, isEq, isNotEq, isLike } from './filter'
import {
findProp,
randomTakes,
checkTypes
} from './utils'
import {
isGreater,
isLess,
isLessOrEq,
isGreaterOrEq,
isEq,
isNotEq,
isLike
} from './filter'
import error from './errors'

@@ -9,4 +21,4 @@

this.data = array.slice(0) // https://jsperf.com/cloning-arrays/3
this.selector = selector
this.caret = 0
this.selector = selector
}

@@ -135,2 +147,15 @@

pick (value) {
if (!value) return this
if (typeof value !== 'string') error('NO_STR_VALUE')
value = value.toLowerCase()
if (value === 'even') return new DataField(this.data.filter((el, i) => !(i % 2)))
if (value === 'odd') return new DataField(this.data.filter((el, i) => i % 2))
if (value.slice(-1) === 'n' && !!Number(value.slice(0, -1))) {
const rule = Number(value.slice(0, -1))
return new DataField(this.data.filter((el, i) => !(i % rule)))
}
error('BAD_PICK_ARG')
}
sort ({ by, order = 'asc', type } = {}) {

@@ -137,0 +162,0 @@ const prop = this.__findFirstOccurrence(by)

@@ -15,2 +15,6 @@ export default function error (code) {

throw new Error('DataField selector should be passed as an argument when using math methods')
case 'NO_STR_VALUE':
throw new Error('DataField selector .pick() expects a string')
case 'BAD_PICK_ARG':
throw new Error('DataField selector .pick() should have a proper argument value — "even", "odd" or "{number}n" (i.e. 3n for every third element)')
default:

@@ -17,0 +21,0 @@ throw new Error('DataField error')

@@ -85,4 +85,35 @@ import DataField from '../src/datafield'

})
describe('Pick Test', function () {
it('should keep even elements', function () {
expect(dataField.pick('even').length).toEqual(50)
})
it('should keep even elements', function () {
expect(dataField.pick('odd').length).toEqual(50)
})
it('should keep every 3rd element', function () {
expect(dataField.pick('3n').length).toEqual(34)
})
it('should keep every 5th element', function () {
expect(dataField.pick('5n').length).toEqual(20)
})
it('should throw an error if argument is not a string', function () {
expect(() => dataField.pick(42)).toThrow('DataField selector .pick() expects a string')
})
it('should throw an error if argument is not right', function () {
expect(() => dataField.pick("wrong string")).toThrow('DataField selector .pick() should have a proper argument value — "even", "odd" or "{number}n" (i.e. 3n for every third element)')
})
it('should return this if no argument provided', function () {
expect(dataField.pick().length).toEqual(100)
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc