data-filter
Advanced tools
Comparing version 2.0.0-rc.8 to 2.0.0-rc.9
@@ -1,2 +0,2 @@ | ||
/** @license Data-Engine v2.0.0-rc.8 | ||
/** @license Data-Engine v2.0.0-rc.9 | ||
* data-filter.development.js | ||
@@ -16,70 +16,5 @@ * | ||
/* eslint-disable */ | ||
var FilterValue = require('filter-value'); | ||
var Sort = require('data-sort'); | ||
// WARNING NOT BEST PRACTICE!!! CAN BE VERY DANGEROUS!!! | ||
Number.prototype.$ = {}; | ||
Number.prototype.$.isGreater = function (toCompare) { | ||
return this >= toCompare; | ||
}; | ||
Number.prototype.$.isLess = function (toCompare) { | ||
return this <= toCompare; | ||
}; | ||
String.prototype.$ = {}; | ||
String.prototype.$.isGreater = function (toCompare) { | ||
return this >= toCompare; | ||
}; | ||
String.prototype.$.isLess = function (toCompare) { | ||
return this <= toCompare; | ||
}; | ||
Date.prototype.$ = {}; | ||
Date.prototype.$.compare = function (toCompare) { | ||
return this.getTime() === toCompare.getTime(); | ||
}; | ||
Date.prototype.$.isGreater = function (toCompare) { | ||
return this.getTime() >= toCompare.getTime(); | ||
}; | ||
Date.prototype.$.isLess = function (toCompare) { | ||
return this.getTime() <= toCompare.getTime(); | ||
}; | ||
var specials = ['-', '[', ']', '/', '{', '}', '(', ')', '*', '+', '?', '.', '\\', '^', '$', '|']; | ||
var regex = RegExp('[' + specials.join('\\') + ']', 'g'); | ||
/** | ||
* Replacing unwanted characters with \\ | ||
* | ||
* @export | ||
* @param {string} string string which you want to escape | ||
* @returns {string} escaped values | ||
*/ | ||
function regexEscape(string) { | ||
return string.replace(regex, '\\$&'); | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
@@ -109,639 +44,3 @@ if (!(instance instanceof Constructor)) { | ||
var staticTypes = ['number', 'string', 'regexp', 'boolean']; | ||
// TODO: check static types | ||
var FilterValue = function () { | ||
/** | ||
* Creates an instance of FilterValue. | ||
* string, number, regexp, function, array of items mentioned before | ||
* | ||
* @param {string} name - name of filter | ||
* @param {any} item - value | ||
* @param {any} type - type of item | ||
* @memberOf FilterValue | ||
*/ | ||
function FilterValue() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var item = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
classCallCheck(this, FilterValue); | ||
_initialiseProps.call(this); | ||
this.originaItem = null; | ||
this.Name = name; | ||
if (type !== null) { | ||
this.Type = type; | ||
} | ||
if (item === null) { | ||
return; | ||
} | ||
this.Value = item; | ||
} | ||
/** | ||
* Preparing item for right validation. | ||
* | ||
* @param {any} item - filter value! | ||
* | ||
* @return {Array/any} right element. | ||
* @memberOf FilterValue | ||
*/ | ||
FilterValue.prototype.prepareItem = function prepareItem(item) { | ||
switch (this.type) { | ||
case 'array': | ||
if (Array.isArray(item[item.length - 1])) { | ||
throw new TypeError('Array in Array isn\'t supported!'); | ||
} | ||
return item.map(function (value) { | ||
return new FilterValue(item.Name, value); | ||
}); | ||
default: | ||
if (this.staticType) { | ||
return this.RETYPE[this.staticType](item); | ||
} | ||
return item; | ||
} | ||
}; | ||
/** | ||
* Setter for name | ||
* | ||
* @param {string} name new name | ||
* @memberOf FilterValue | ||
*/ | ||
createClass(FilterValue, [{ | ||
key: 'Name', | ||
set: function set$$1(name) { | ||
if (typeof name === 'string') { | ||
this.name = name; | ||
} | ||
} | ||
/** | ||
* Getter for name | ||
* | ||
* @readonly | ||
* @return {string} name | ||
* @memberOf FilterValue | ||
*/ | ||
, | ||
get: function get$$1() { | ||
return this.name; | ||
} | ||
/** | ||
* Validation if possible to static type item | ||
* @param {any} item | ||
* @return {boolean} true when it's possible to retype | ||
* @memberOf FilterValue | ||
*/ | ||
}, { | ||
key: 'Type', | ||
/** | ||
* Setter for type | ||
* | ||
* @param {string} type new static type | ||
* | ||
* @memberOf FilterValue | ||
*/ | ||
set: function set$$1(type) { | ||
if (this.validStaticType(type)) { | ||
this.staticType = type; | ||
} | ||
} | ||
/** | ||
* Remove static Type | ||
* | ||
* | ||
* @memberOf FilterValue | ||
*/ | ||
}, { | ||
key: 'Value', | ||
/** Setter for new value | ||
* Update filter value | ||
* | ||
* @param {any} item new item | ||
* @memberOf FilterValue | ||
*/ | ||
set: function set$$1(item) { | ||
this.originaItem = item; | ||
this.type = this.checkValidity(item); | ||
if (this.type) { | ||
this.item = this.prepareItem(item); | ||
this.compareFunc = this.TYPES[this.type]; | ||
} else { | ||
throw new TypeError('item isn\'t valid filter value, possible types are string, RegExp, number, function, array of types mentioned before.'); | ||
} | ||
} | ||
/** | ||
* Getter for original value | ||
*/ | ||
, | ||
get: function get$$1() { | ||
return this.originaItem; | ||
} | ||
/** | ||
* Basic exact compare. `===`! for number and strings. | ||
* | ||
* @param {any} toCompare - item which will be compared. | ||
* @return {boolean} compare value | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Compares dates | ||
* @see ./update-prototype | ||
* | ||
* @param {Date} | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Basic regexp test | ||
* | ||
* @param {any} toCompare - item which will be compared. | ||
* @return {boolean} compare value | ||
* | ||
* @memberOf FilterValue | ||
*/ | ||
/** comparing array of FilterValue! | ||
* | ||
* @param {any} toCompare - item which will be compared. | ||
* | ||
* @return {boolean} compare value | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Function compare when user give compare item as function! | ||
* | ||
* @param {any} toCompare - item which will be compared. | ||
* | ||
* @return {boolean} compare value | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Compares range | ||
* @see ./update-prototype | ||
* | ||
* @param {any} toCompare item which will be compared | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Basic types of testable items. | ||
* Enum for data types | ||
* | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Try to retype to number | ||
* | ||
* @param {any} item which should be retyped | ||
* @return {number} retyped number | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Retype anything to string | ||
* | ||
* @param {any} item which should be retyped | ||
* @return {string} retyped string | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Retype anything to bool | ||
* | ||
* @param {any} item which should be retyped | ||
* @return {bool} retyped bool | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Enum for retype | ||
* | ||
* | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Applying filter to item which will return true/false. True when it should be ignored. | ||
* | ||
* @param {any} toCompare - item which will be compared. | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* Checking validity of supported types | ||
* valid types are | ||
* string, number, regexp, function, array of items mentioned before! | ||
* | ||
* @param {any} item | ||
* @return {string/null} return type if exist | ||
* @memberOf FilterValue | ||
*/ | ||
/** | ||
* checkBasicTypes checking basic types | ||
* | ||
* @param {any} item | ||
* @return {string/null} name of type if exist | ||
* @memberOf FilterValue | ||
*/ | ||
}]); | ||
return FilterValue; | ||
}(); | ||
FilterValue.regexEscape = regexEscape; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this = this; | ||
this.validStaticType = function (item) { | ||
return staticTypes.some(function (key) { | ||
return key === item; | ||
}); | ||
}; | ||
this.removeType = function () { | ||
_this.staticType = null; | ||
}; | ||
this.basicCompare = function (toCompare) { | ||
return _this.item === toCompare; | ||
}; | ||
this.dateCompare = function (toCompare) { | ||
return _this.item.$.compare(toCompare); | ||
}; | ||
this.regexpCompare = function (toCompare) { | ||
return _this.item.test('' + toCompare); | ||
}; | ||
this.arrayCompare = function (toCompare) { | ||
return _this.item.some(function (itm) { | ||
return itm.compare(toCompare); | ||
}); | ||
}; | ||
this.funcCompare = function (toCompare) { | ||
return _this.item(toCompare); | ||
}; | ||
this.rangeCompare = function (toCompare) { | ||
return _this.item.from.$.isLess(toCompare) && _this.item.to.$.isGreater(toCompare); | ||
}; | ||
this.TYPES = { | ||
boolean: this.basicCompare, | ||
string: this.basicCompare, | ||
number: this.basicCompare, | ||
date: this.dateCompare, | ||
array: this.arrayCompare, | ||
regexp: this.regexpCompare, | ||
func: this.funcCompare, | ||
range: this.rangeCompare | ||
}; | ||
this.numberRetype = function (item) { | ||
return parseFloat(item); | ||
}; | ||
this.stringRetype = function (item) { | ||
return '' + item; | ||
}; | ||
this.booleanRetype = function (item) { | ||
return !!item; | ||
}; | ||
this.RETYPE = { | ||
number: this.numberRetype, | ||
string: this.stringRetype, | ||
boolean: this.booleanRetype }; | ||
this.compare = function (toCompare) { | ||
return _this.compareFunc(toCompare); | ||
}; | ||
this.checkValidity = function (item) { | ||
var type = _this.checkRangeAbleTypes(item); | ||
if (!type) { | ||
switch (typeof item === 'undefined' ? 'undefined' : _typeof(item)) { | ||
case 'boolean': | ||
type = 'boolean'; | ||
break; | ||
case 'function': | ||
type = 'func'; | ||
break; | ||
case 'object': | ||
if (Array.isArray(item)) { | ||
type = 'array'; | ||
} else if (item instanceof RegExp) { | ||
type = 'regexp'; | ||
} else if (item.from && item.to) { | ||
if (_this.checkRangeAbleTypes(item.from) === _this.checkRangeAbleTypes(item.to)) { | ||
type = 'range'; | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return type; | ||
}; | ||
this.checkRangeAbleTypes = function (item) { | ||
var type = null; | ||
switch (typeof item === 'undefined' ? 'undefined' : _typeof(item)) { | ||
case 'string': | ||
type = 'string'; | ||
break; | ||
case 'number': | ||
type = 'number'; | ||
break; | ||
case 'object': | ||
if (item instanceof Date) { | ||
type = 'date'; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
return type; | ||
}; | ||
}; | ||
var filterValue = Object.freeze({ | ||
default: FilterValue | ||
}); | ||
var FilterValue$2 = ( filterValue && FilterValue ) || filterValue; | ||
var filterValue$1 = FilterValue$2.default ? FilterValue$2.default : FilterValue$2; | ||
/** | ||
* Sort engine, just basic sort provider | ||
* | ||
* @export | ||
* @class Sort | ||
*/ | ||
var Sort = function () { | ||
/** | ||
* Creates an instance of Sort. | ||
* @param {any} data - original data | ||
* @param {string} [primaryKey=null] - primary key which will be fallback when keys are equals | ||
* @param {function} [sortFunction=null] - custom sort function | ||
* | ||
* @memberOf Sort | ||
*/ | ||
function Sort() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var primaryKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var sortFunction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
classCallCheck(this, Sort); | ||
_initialiseProps$1.call(this); | ||
this.currentName = null; | ||
this.sortFunc = this.defaultSort; | ||
this.setSortFunction(sortFunction); | ||
this.setPrimaryKey(primaryKey); | ||
this.setData(data, true); | ||
} | ||
/** | ||
* Update data, refresh old data with new. | ||
* | ||
* @param {any} data new data | ||
* @param {boolean} shouldSort should be resorted | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Setter for custom function | ||
* | ||
* @param {function} func your custom sort function | ||
* @memberOf Sort | ||
*/ | ||
createClass(Sort, [{ | ||
key: 'SortFunction', | ||
set: function set$$1(func) { | ||
this.setSortFunction(func); | ||
} | ||
/** | ||
* Setter for primary key (fallback key) | ||
* | ||
* @param {string} key primary key | ||
* @memberOf Sort | ||
*/ | ||
}, { | ||
key: 'PrimaryKey', | ||
set: function set$$1(key) { | ||
this.setPrimaryKey(key); | ||
} | ||
/** | ||
* Remover primary key set to default | ||
* | ||
* | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Setup default sort function | ||
* | ||
* | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Compare primary key | ||
* Fallback function when current values are equal. | ||
* @param {any} a - first item | ||
* @param {any} b - second item | ||
* @return {number} position of elements | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Compare by current name | ||
* | ||
* @param {any} a - first item | ||
* @param {any} b - second item | ||
* @return {number} position of elements | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* sort by name, sets new name and check if we need to only reverse | ||
* | ||
* @param {string} name key for sort | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* default sort with key | ||
* Default sorting function when user won't add own function. | ||
* | ||
* @param {any} a - first item | ||
* @param {any} b - second item | ||
* @return {number} position of elements | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* default sort | ||
* Default sorting function when user won't add own function. | ||
* | ||
* @param {any} a - first item | ||
* @param {any} b - second item | ||
* @return {number} position of elements | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Well just sort function. when we need resort. | ||
* | ||
* @return {Array} sorted data | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* well just reverse sorted array | ||
* | ||
* @return {Array} reversed data | ||
* @memberOf Sort | ||
*/ | ||
/** | ||
* Getter for data | ||
* | ||
* | ||
* @memberOf Sort | ||
*/ | ||
}]); | ||
return Sort; | ||
}(); | ||
var _initialiseProps$1 = function _initialiseProps() { | ||
var _this = this; | ||
this.setData = function (data) { | ||
var shouldSort = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
_this.data = data; | ||
if (shouldSort) { | ||
return _this.sortData(); | ||
} | ||
return _this.data; | ||
}; | ||
this.setSortFunction = function (func) { | ||
if (typeof func === 'function') { | ||
_this.sortFunc = func; | ||
_this.isCustomFunction = true; | ||
} | ||
}; | ||
this.setPrimaryKey = function (key) { | ||
if (_this.isCustomFunction) { | ||
return; | ||
} | ||
if (typeof key === 'string' && key.length > 0) { | ||
_this.primaryKey = key; | ||
if (_this.currentName === null) { | ||
_this.currentName = key; | ||
} | ||
_this.sortFunc = _this.defaultSortWithKey; | ||
} | ||
}; | ||
this.removePrimaryKey = function () { | ||
_this.primaryKey = ''; | ||
if (!_this.isCustomFunction) { | ||
_this.sortFunc = _this.defaultSort; | ||
} | ||
}; | ||
this.setDefaultSort = function () { | ||
_this.isCustomFunction = false; | ||
_this.sortFunc = _this.primaryKey ? _this.defaultSortWithKey : _this.defaultSort; | ||
}; | ||
this.comparePrimaryKey = function (a, b) { | ||
return a[_this.primaryKey] > b[_this.primaryKey]; | ||
}; | ||
this.compare = function (a, b) { | ||
return a[_this.currentName] > b[_this.currentName]; | ||
}; | ||
this.sortBy = function (name) { | ||
if (_this.currentName === name) { | ||
return _this.reverseData(); | ||
} | ||
_this.currentName = name; | ||
return _this.sortData(); | ||
}; | ||
this.defaultSortWithKey = function (a, b) { | ||
if (a[_this.currentName] === b[_this.currentName]) { | ||
return _this.comparePrimaryKey(a, b); | ||
} | ||
return _this.compare(a, b); | ||
}; | ||
this.defaultSort = function (a, b) { | ||
return _this.compare(a, b); | ||
}; | ||
this.sortData = function () { | ||
if (_this.currentName) { | ||
_this.data = _this.data.sort(_this.sortFunc); | ||
} | ||
return _this.data; | ||
}; | ||
this.reverseData = function () { | ||
_this.data = _this.data.reverse(); | ||
return _this.data; | ||
}; | ||
this.getData = function () { | ||
return _this.data; | ||
}; | ||
}; | ||
var dataSort = Object.freeze({ | ||
default: Sort | ||
}); | ||
var Sort$2 = ( dataSort && Sort ) || dataSort; | ||
var dataSort$1 = Sort$2.default ? Sort$2.default : Sort$2; | ||
/** | ||
* Filter engine | ||
@@ -764,3 +63,3 @@ * | ||
_initialiseProps$2.call(this); | ||
_initialiseProps.call(this); | ||
@@ -888,3 +187,3 @@ this.filtered = data; | ||
set: function set$$1(sortEngine) { | ||
if (sortEngine instanceof dataSort$1) { | ||
if (sortEngine instanceof Sort) { | ||
this.sortEngine = sortEngine; | ||
@@ -909,3 +208,3 @@ this.updateFce = this.filterWSort; | ||
var _initialiseProps$2 = function _initialiseProps() { | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this = this; | ||
@@ -928,3 +227,3 @@ | ||
// Exception when item isn't filterValue! | ||
if (!(item instanceof filterValue$1)) { | ||
if (!(item instanceof FilterValue)) { | ||
throw new TypeError(item + ' has to have filterValue instance'); | ||
@@ -931,0 +230,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/** @license Data-Engine v2.0.0-rc.8 | ||
/** @license Data-Engine v2.0.0-rc.9 | ||
* data-filter.production.min.js | ||
@@ -9,25 +9,11 @@ * | ||
*/ | ||
'use strict';var d=d||{};d.scope={};d.ASSUME_ES5=!1;d.ASSUME_NO_NATIVE_MAP=!1;d.ASSUME_NO_NATIVE_SET=!1;d.defineProperty=d.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};d.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};d.global=d.getGlobal(this);d.SYMBOL_PREFIX="jscomp_symbol_"; | ||
d.initSymbol=function(){d.initSymbol=function(){};d.global.Symbol||(d.global.Symbol=d.Symbol)};d.Symbol=function(){var a=0;return function(b){return d.SYMBOL_PREFIX+(b||"")+a++}}();d.initSymbolIterator=function(){d.initSymbol();var a=d.global.Symbol.iterator;a||(a=d.global.Symbol.iterator=d.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&d.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return d.arrayIterator(this)}});d.initSymbolIterator=function(){}}; | ||
d.arrayIterator=function(a){var b=0;return d.iteratorPrototype(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})};d.iteratorPrototype=function(a){d.initSymbolIterator();a={next:a};a[d.global.Symbol.iterator]=function(){return this};return a}; | ||
d.iteratorFromArray=function(a,b){d.initSymbolIterator();a instanceof String&&(a+="");var c=0,e={next:function(){if(c<a.length){var f=c++;return{value:b(f,a[f]),done:!1}}e.next=function(){return{done:!0,value:void 0}};return e.next()}};e[Symbol.iterator]=function(){return e};return e}; | ||
d.polyfill=function(a,b){if(b){var c=d.global;a=a.split(".");for(var e=0;e<a.length-1;e++){var f=a[e];f in c||(c[f]={});c=c[f]}a=a[a.length-1];e=c[a];b=b(e);b!=e&&null!=b&&d.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};d.polyfill("Array.prototype.keys",function(a){return a?a:function(){return d.iteratorFromArray(this,function(a){return a})}},"es6","es3");Number.prototype.$={};Number.prototype.$.isGreater=function(a){return this>=a}; | ||
Number.prototype.$.isLess=function(a){return this<=a};String.prototype.$={};String.prototype.$.isGreater=function(a){return this>=a};String.prototype.$.isLess=function(a){return this<=a};Date.prototype.$={};Date.prototype.$.compare=function(a){return this.getTime()===a.getTime()};Date.prototype.$.isGreater=function(a){return this.getTime()>=a.getTime()};Date.prototype.$.isLess=function(a){return this.getTime()<=a.getTime()}; | ||
var g=/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,h="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"===typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};function k(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function");} | ||
var l=function(){function a(a,c){for(var b=0;b<c.length;b++){var f=c[b];f.enumerable=f.enumerable||!1;f.configurable=!0;"value"in f&&(f.writable=!0);Object.defineProperty(a,f.key,f)}}return function(b,c,e){c&&a(b.prototype,c);e&&a(b,e);return b}}(),m=["number","string","regexp","boolean"],p=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]: | ||
null;k(this,a);n.call(this);this.originaItem=null;this.Name=b;null!==e&&(this.Type=e);null!==c&&(this.Value=c)}a.prototype.prepareItem=function(b){switch(this.type){case "array":if(Array.isArray(b[b.length-1]))throw new TypeError("Array in Array isn't supported!");return b.map(function(c){return new a(b.Name,c)});default:return this.staticType?this.RETYPE[this.staticType](b):b}};l(a,[{key:"Name",set:function(a){"string"===typeof a&&(this.name=a)},get:function(){return this.name}},{key:"Type",set:function(a){this.validStaticType(a)&& | ||
(this.staticType=a)}},{key:"Value",set:function(a){this.originaItem=a;if(this.type=this.checkValidity(a))this.item=this.prepareItem(a),this.compareFunc=this.TYPES[this.type];else throw new TypeError("item isn't valid filter value, possible types are string, RegExp, number, function, array of types mentioned before.");},get:function(){return this.originaItem}}]);return a}();p.regexEscape=function(a){return a.replace(g,"\\$\x26")}; | ||
function n(){var a=this;this.validStaticType=function(a){return m.some(function(b){return b===a})};this.removeType=function(){a.staticType=null};this.basicCompare=function(b){return a.item===b};this.dateCompare=function(b){return a.item.$.compare(b)};this.regexpCompare=function(b){return a.item.test(""+b)};this.arrayCompare=function(b){return a.item.some(function(a){return a.compare(b)})};this.funcCompare=function(b){return a.item(b)};this.rangeCompare=function(b){return a.item.from.$.isLess(b)&& | ||
a.item.to.$.isGreater(b)};this.TYPES={boolean:this.basicCompare,string:this.basicCompare,number:this.basicCompare,date:this.dateCompare,array:this.arrayCompare,regexp:this.regexpCompare,func:this.funcCompare,range:this.rangeCompare};this.numberRetype=function(a){return parseFloat(a)};this.stringRetype=function(a){return""+a};this.booleanRetype=function(a){return!!a};this.RETYPE={number:this.numberRetype,string:this.stringRetype,boolean:this.booleanRetype};this.compare=function(b){return a.compareFunc(b)}; | ||
this.checkValidity=function(b){var c=a.checkRangeAbleTypes(b);if(!c)switch("undefined"===typeof b?"undefined":h(b)){case "boolean":c="boolean";break;case "function":c="func";break;case "object":Array.isArray(b)?c="array":b instanceof RegExp?c="regexp":b.from&&b.to&&a.checkRangeAbleTypes(b.from)===a.checkRangeAbleTypes(b.to)&&(c="range")}return c};this.checkRangeAbleTypes=function(a){var b=null;switch("undefined"===typeof a?"undefined":h(a)){case "string":b="string";break;case "number":b="number"; | ||
break;case "object":a instanceof Date&&(b="date")}return b}} | ||
var q=Object.freeze({default:p}),r=q&&p||q,t=r.default?r.default:r,v=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;k(this,a);u.call(this);this.currentName=null;this.sortFunc=this.defaultSort;this.setSortFunction(e);this.setPrimaryKey(c);this.setData(b,!0)}l(a,[{key:"SortFunction",set:function(a){this.setSortFunction(a)}},{key:"PrimaryKey", | ||
set:function(a){this.setPrimaryKey(a)}}]);return a}(); | ||
function u(){var a=this;this.setData=function(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!1;a.data=b;return c?a.sortData():a.data};this.setSortFunction=function(b){"function"===typeof b&&(a.sortFunc=b,a.isCustomFunction=!0)};this.setPrimaryKey=function(b){!a.isCustomFunction&&"string"===typeof b&&0<b.length&&(a.primaryKey=b,null===a.currentName&&(a.currentName=b),a.sortFunc=a.defaultSortWithKey)};this.removePrimaryKey=function(){a.primaryKey="";a.isCustomFunction||(a.sortFunc= | ||
a.defaultSort)};this.setDefaultSort=function(){a.isCustomFunction=!1;a.sortFunc=a.primaryKey?a.defaultSortWithKey:a.defaultSort};this.comparePrimaryKey=function(b,c){return b[a.primaryKey]>c[a.primaryKey]};this.compare=function(b,c){return b[a.currentName]>c[a.currentName]};this.sortBy=function(b){if(a.currentName===b)return a.reverseData();a.currentName=b;return a.sortData()};this.defaultSortWithKey=function(b,c){return b[a.currentName]===c[a.currentName]?a.comparePrimaryKey(b,c):a.compare(b,c)}; | ||
this.defaultSort=function(b,c){return a.compare(b,c)};this.sortData=function(){a.currentName&&(a.data=a.data.sort(a.sortFunc));return a.data};this.reverseData=function(){a.data=a.data.reverse();return a.data};this.getData=function(){return a.data}} | ||
var w=Object.freeze({default:v}),x=w&&v||w,y=x.default?x.default:x,A=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;k(this,a);z.call(this);this.filtered=b;this.filters={};this.SortEngine=c;this.Data=b}l(a,[{key:"Data",set:function(a){this.setData(a)},get:function(){return this.data}},{key:"FilteredData",get:function(){return this.getFilteredData()}},{key:"SortEngine",set:function(a){a instanceof | ||
y?(this.sortEngine=a,this.updateFce=this.filterWSort):(this.sortEngine=null,this.updateFce=this.filterWOSort)},get:function(){return this.sortEngine}}]);return a}(); | ||
function z(){var a=this;this.updateFce=this.filterWOSort;this.setData=function(b){a.data=b;return a.updateFilter()};this.update=function(){for(var b=arguments.length,c=Array(b),e=0;e<b;e++)c[e]=arguments[e];var f=a.getFilteredData;c.forEach(function(b){if(!(b instanceof t))throw new TypeError(b+" has to have filterValue instance");a.filters[b.Name]=b;f=a.updateFilter});return f()};this.removeFilters=function(){for(var b=arguments.length,c=Array(b),e=0;e<b;e++)c[e]=arguments[e];var f=a.getFilteredData; | ||
c.forEach(function(b){b="string"===typeof b?b:b.Name;a.filters[b]&&(delete a.filters[b],f=a.updateFilter)});return f()};this.clearFilters=function(){a.filters={};a.filtered=a.data;return a.getFilteredData()};this.updateFilter=function(){if(null===a.data)throw Error("Data are null and cannot be filtered!");a.filtered=a.data.filter(a.filterAll);return a.getFilteredData()};this.filterAll=function(b){return Object.keys(a.filters).every(function(c){return a.filters[c].compare(b[c])})};this.getFilteredData= | ||
function(){return a.updateFce()};this.filterWOSort=function(){return a.filtered};this.filterWSort=function(){return a.SortEngine.setData(a.filtered)};this.getFilter=function(b){return a.filters[b]?a.filters[b]:null}}var B=Object.freeze({default:A}),C=B&&A||B;module.exports=C.default?C.default:C; | ||
'use strict';var c=c||{};c.scope={};c.ASSUME_ES5=!1;c.ASSUME_NO_NATIVE_MAP=!1;c.ASSUME_NO_NATIVE_SET=!1;c.defineProperty=c.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)};c.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};c.global=c.getGlobal(this);c.SYMBOL_PREFIX="jscomp_symbol_"; | ||
c.initSymbol=function(){c.initSymbol=function(){};c.global.Symbol||(c.global.Symbol=c.Symbol)};c.Symbol=function(){var a=0;return function(b){return c.SYMBOL_PREFIX+(b||"")+a++}}();c.initSymbolIterator=function(){c.initSymbol();var a=c.global.Symbol.iterator;a||(a=c.global.Symbol.iterator=c.global.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&c.defineProperty(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return c.arrayIterator(this)}});c.initSymbolIterator=function(){}}; | ||
c.arrayIterator=function(a){var b=0;return c.iteratorPrototype(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})};c.iteratorPrototype=function(a){c.initSymbolIterator();a={next:a};a[c.global.Symbol.iterator]=function(){return this};return a}; | ||
c.iteratorFromArray=function(a,b){c.initSymbolIterator();a instanceof String&&(a+="");var d=0,e={next:function(){if(d<a.length){var f=d++;return{value:b(f,a[f]),done:!1}}e.next=function(){return{done:!0,value:void 0}};return e.next()}};e[Symbol.iterator]=function(){return e};return e}; | ||
c.polyfill=function(a,b){if(b){var d=c.global;a=a.split(".");for(var e=0;e<a.length-1;e++){var f=a[e];f in d||(d[f]={});d=d[f]}a=a[a.length-1];e=d[a];b=b(e);b!=e&&null!=b&&c.defineProperty(d,a,{configurable:!0,writable:!0,value:b})}};c.polyfill("Array.prototype.keys",function(a){return a?a:function(){return c.iteratorFromArray(this,function(a){return a})}},"es6","es3"); | ||
var g=require("filter-value"),h=require("data-sort"),k=function(){function a(a,d){for(var b=0;b<d.length;b++){var f=d[b];f.enumerable=f.enumerable||!1;f.configurable=!0;"value"in f&&(f.writable=!0);Object.defineProperty(a,f.key,f)}}return function(b,d,e){d&&a(b.prototype,d);e&&a(b,e);return b}}(),m=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;if(!(this instanceof a))throw new TypeError("Cannot call a class as a function"); | ||
l.call(this);this.filtered=b;this.filters={};this.SortEngine=d;this.Data=b}k(a,[{key:"Data",set:function(a){this.setData(a)},get:function(){return this.data}},{key:"FilteredData",get:function(){return this.getFilteredData()}},{key:"SortEngine",set:function(a){a instanceof h?(this.sortEngine=a,this.updateFce=this.filterWSort):(this.sortEngine=null,this.updateFce=this.filterWOSort)},get:function(){return this.sortEngine}}]);return a}(); | ||
function l(){var a=this;this.updateFce=this.filterWOSort;this.setData=function(b){a.data=b;return a.updateFilter()};this.update=function(){for(var b=arguments.length,d=Array(b),e=0;e<b;e++)d[e]=arguments[e];var f=a.getFilteredData;d.forEach(function(b){if(!(b instanceof g))throw new TypeError(b+" has to have filterValue instance");a.filters[b.Name]=b;f=a.updateFilter});return f()};this.removeFilters=function(){for(var b=arguments.length,d=Array(b),e=0;e<b;e++)d[e]=arguments[e];var f=a.getFilteredData; | ||
d.forEach(function(b){b="string"===typeof b?b:b.Name;a.filters[b]&&(delete a.filters[b],f=a.updateFilter)});return f()};this.clearFilters=function(){a.filters={};a.filtered=a.data;return a.getFilteredData()};this.updateFilter=function(){if(null===a.data)throw Error("Data are null and cannot be filtered!");a.filtered=a.data.filter(a.filterAll);return a.getFilteredData()};this.filterAll=function(b){return Object.keys(a.filters).every(function(d){return a.filters[d].compare(b[d])})};this.getFilteredData= | ||
function(){return a.updateFce()};this.filterWOSort=function(){return a.filtered};this.filterWSort=function(){return a.SortEngine.setData(a.filtered)};this.getFilter=function(b){return a.filters[b]?a.filters[b]:null}}var n=Object.freeze({default:m}),p=n&&m||n;module.exports=p.default?p.default:p; |
{ | ||
"name": "data-filter", | ||
"description": "Data engine is small data management lib for some sort and filter.", | ||
"version": "2.0.0-rc.8", | ||
"version": "2.0.0-rc.9", | ||
"keywords": [ | ||
@@ -49,4 +49,4 @@ "Data", | ||
"loose-envify": "^1.1.0", | ||
"filter-value": "^2.0.0-rc.8", | ||
"data-sort": "^2.0.0-rc.8" | ||
"filter-value": "^2.0.0-rc.9", | ||
"data-sort": "^2.0.0-rc.9" | ||
}, | ||
@@ -53,0 +53,0 @@ "browserify": { |
@@ -1,2 +0,2 @@ | ||
/** @license Engine v2.0.0-rc.8 | ||
/** @license Engine v2.0.0-rc.9 | ||
* data-filter.development.js | ||
@@ -501,2 +501,16 @@ * | ||
/* eslint-disable */ | ||
function logf() { | ||
console.log.call(arguments); | ||
} | ||
function noop() {} | ||
var log = noop; | ||
{ | ||
log = logf; | ||
} | ||
/** | ||
@@ -654,2 +668,3 @@ * Sort engine, just basic sort provider | ||
log('setData', data, 'should sort', shouldSort); | ||
_this.data = data; | ||
@@ -670,5 +685,7 @@ if (shouldSort) { | ||
this.setPrimaryKey = function (key) { | ||
log('setPrimaryKey'); | ||
if (_this.isCustomFunction) { | ||
return; | ||
} | ||
log('primaryKey Continue'); | ||
if (typeof key === 'string' && key.length > 0) { | ||
@@ -679,2 +696,3 @@ _this.primaryKey = key; | ||
} | ||
log(_this.currentName, _this.primaryKey); | ||
_this.sortFunc = _this.defaultSortWithKey; | ||
@@ -724,2 +742,3 @@ } | ||
this.sortData = function () { | ||
log(_this.currentName); | ||
if (_this.currentName) { | ||
@@ -726,0 +745,0 @@ _this.data = _this.data.sort(_this.sortFunc); |
@@ -1,2 +0,2 @@ | ||
/** @license Data-Engine v2.0.0-rc.8 | ||
/** @license Data-Engine v2.0.0-rc.9 | ||
* data-filter.production.min.js | ||
@@ -3,0 +3,0 @@ * |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
50930
1191
3
2
Updateddata-sort@^2.0.0-rc.9
Updatedfilter-value@^2.0.0-rc.9