data-engine
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-engine.development.js | ||
@@ -16,70 +16,6 @@ * | ||
/* eslint-disable */ | ||
var Filter = require('data-filter'); | ||
var Sort = require('data-sort'); | ||
var FilterValue = require('filter-value'); | ||
// 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,893 +45,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 | ||
* | ||
* @class Filter | ||
*/ | ||
var Filter = function () { | ||
/** | ||
* Creates an instance of Filter. | ||
* @param {any} data - initial data | ||
* | ||
* @memberOf Filter | ||
*/ | ||
function Filter() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var sortEngine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
classCallCheck(this, Filter); | ||
_initialiseProps$2.call(this); | ||
this.filtered = data; | ||
this.filters = {}; | ||
this.SortEngine = sortEngine; | ||
this.Data = data; | ||
} | ||
/** | ||
* Setter for data | ||
* | ||
* @param {Array} data new data | ||
* @memberOf Filter | ||
*/ | ||
createClass(Filter, [{ | ||
key: 'Data', | ||
/** | ||
* Setter for data | ||
* | ||
* @param {Array} data new data | ||
* @memberOf Filter | ||
*/ | ||
set: function set$$1(data) { | ||
this.setData(data); | ||
} | ||
/** | ||
* Setter for data | ||
* | ||
* @param {Array} data new data | ||
* @memberOf Filter | ||
*/ | ||
, | ||
get: function get$$1() { | ||
return this.data; | ||
} | ||
/** | ||
* Add or modify filter value | ||
* | ||
* | ||
* @param {Array} items - array of filter items | ||
* @throws {TypeError} when item isn't instance of FilterValue | ||
* @return {Array} new filtered array | ||
* @memberOf Filter | ||
*/ | ||
/** | ||
* Remove one or as many filters as you add value | ||
* only updating when at least one filter was removed | ||
* @param {object} item - filter item | ||
* | ||
* @return {Array} new filtered array | ||
* @memberOf Filter | ||
*/ | ||
/** | ||
* Clears all filters | ||
* | ||
* @return {Array} new filtered array | ||
* @memberOf Filter | ||
*/ | ||
/** | ||
* Update filtered array. | ||
* | ||
* @return {Array} new filtered array | ||
* @memberOf Filter | ||
*/ | ||
/** | ||
* Filter line by all criteria. | ||
* | ||
* @param {object} line - line from original data. | ||
* | ||
* @return {bool} | ||
* @memberOf Filter | ||
*/ | ||
/** | ||
* Simple getter | ||
* | ||
* @returns {array} filtered data | ||
* | ||
* @memberOf Filter | ||
*/ | ||
}, { | ||
key: 'FilteredData', | ||
/** | ||
* Simple getter | ||
* | ||
* @returns {array} filtered data | ||
* | ||
* @memberOf Filter | ||
*/ | ||
get: function get$$1() { | ||
return this.getFilteredData(); | ||
} | ||
/** | ||
* Helper function when sort is not in filter | ||
*/ | ||
/** | ||
* Helper function with sort; | ||
*/ | ||
/** | ||
* Getter for filter | ||
* @returns {FilterValue | null} return filter value | ||
*/ | ||
}, { | ||
key: 'SortEngine', | ||
/** | ||
* Setter for sort engine | ||
* @param {Sort} sortEngine - instance of Sort | ||
*/ | ||
set: function set$$1(sortEngine) { | ||
if (sortEngine instanceof dataSort$1) { | ||
this.sortEngine = sortEngine; | ||
this.updateFce = this.filterWSort; | ||
} else { | ||
this.sortEngine = null; | ||
this.updateFce = this.filterWOSort; | ||
} | ||
} | ||
/** | ||
* Getter for sort engine | ||
* @returns {Sort} - instance of Sort | ||
*/ | ||
, | ||
get: function get$$1() { | ||
return this.sortEngine; | ||
} | ||
}]); | ||
return Filter; | ||
}(); | ||
var _initialiseProps$2 = function _initialiseProps() { | ||
var _this = this; | ||
this.updateFce = this.filterWOSort; | ||
this.setData = function (data) { | ||
_this.data = data; | ||
return _this.updateFilter(); | ||
}; | ||
this.update = function () { | ||
for (var _len = arguments.length, items = Array(_len), _key = 0; _key < _len; _key++) { | ||
items[_key] = arguments[_key]; | ||
} | ||
var returnFunc = _this.getFilteredData; | ||
items.forEach(function (item) { | ||
// Exception when item isn't filterValue! | ||
if (!(item instanceof filterValue$1)) { | ||
throw new TypeError(item + ' has to have filterValue instance'); | ||
} | ||
_this.filters[item.Name] = item; | ||
returnFunc = _this.updateFilter; | ||
}); | ||
return returnFunc(); | ||
}; | ||
this.removeFilters = function () { | ||
for (var _len2 = arguments.length, names = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
names[_key2] = arguments[_key2]; | ||
} | ||
var returnFunc = _this.getFilteredData; | ||
names.forEach(function (item) { | ||
var removalName = typeof item === 'string' ? item : item.Name; | ||
if (_this.filters[removalName]) { | ||
delete _this.filters[removalName]; | ||
returnFunc = _this.updateFilter; | ||
} | ||
}); | ||
return returnFunc(); | ||
}; | ||
this.clearFilters = function () { | ||
_this.filters = {}; | ||
_this.filtered = _this.data; | ||
return _this.getFilteredData(); | ||
}; | ||
this.updateFilter = function () { | ||
if (_this.data === null) { | ||
throw new Error('Data are null and cannot be filtered!'); | ||
} | ||
_this.filtered = _this.data.filter(_this.filterAll); | ||
return _this.getFilteredData(); | ||
}; | ||
this.filterAll = function (line) { | ||
return Object.keys(_this.filters).every(function (key) { | ||
return _this.filters[key].compare(line[key]); | ||
}); | ||
}; | ||
this.getFilteredData = function () { | ||
return _this.updateFce(); | ||
}; | ||
this.filterWOSort = function () { | ||
return _this.filtered; | ||
}; | ||
this.filterWSort = function () { | ||
return _this.SortEngine.setData(_this.filtered); | ||
}; | ||
this.getFilter = function (name) { | ||
if (_this.filters[name]) { | ||
return _this.filters[name]; | ||
} | ||
return null; | ||
}; | ||
}; | ||
var dataFilter = Object.freeze({ | ||
default: Filter | ||
}); | ||
var Filter$2 = ( dataFilter && Filter ) || dataFilter; | ||
var dataFilter$1 = Filter$2.default ? Filter$2.default : Filter$2; | ||
/** | ||
* Data engine providing sort and filter functionality | ||
@@ -1023,5 +69,5 @@ * | ||
_initialiseProps$3.call(this); | ||
_initialiseProps.call(this); | ||
this.filterEngine = new dataFilter$1(data, new dataSort$1(data, primaryKey, sortFunction)); | ||
this.filterEngine = new Filter(data, new Sort(data, primaryKey, sortFunction)); | ||
} | ||
@@ -1130,7 +176,7 @@ /** | ||
DataEngine.Filter = dataFilter$1; | ||
DataEngine.Sort = dataSort$1; | ||
DataEngine.FilterValue = filterValue$1; | ||
DataEngine.Filter = Filter; | ||
DataEngine.Sort = Sort; | ||
DataEngine.FilterValue = FilterValue; | ||
var _initialiseProps$3 = function _initialiseProps() { | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this = this; | ||
@@ -1195,5 +241,5 @@ | ||
default: DataEngine, | ||
FilterValue: filterValue$1, | ||
Filter: dataFilter$1, | ||
Sort: dataSort$1 | ||
FilterValue: FilterValue, | ||
Filter: Filter, | ||
Sort: Sort | ||
}); | ||
@@ -1200,0 +246,0 @@ |
@@ -1,2 +0,2 @@ | ||
/** @license Data-Engine v2.0.0-rc.8 | ||
/** @license Data-Engine v2.0.0-rc.9 | ||
* data-engine.production.min.js | ||
@@ -9,29 +9,5 @@ * | ||
*/ | ||
'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,D=C.default?C.default:C,F=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);E.call(this);this.filterEngine=new D(b,new y(b,c,e))}l(a,[{key:"FilterEngine",get:function(){return this.filterEngine}},{key:"SortEngine",get:function(){return this.filterEngine.SortEngine}},{key:"Data",get:function(){return this.getData()}}]); | ||
return a}();F.Filter=D;F.Sort=y;F.FilterValue=t; | ||
function E(){var a=this;this.setData=function(b){return a.FilterEngine.setData(b)};this.updateFilters=function(){var b;return(b=a.FilterEngine).update.apply(b,arguments)};this.removeFilters=function(){var b;return(b=a.FilterEngine).removeFilters.apply(b,arguments)};this.clearFilters=function(){return a.FilterEngine.clearFilters()};this.setSortFunction=function(b){return a.SortEngine.setSortFunction(b)};this.setPrimaryKey=function(b){return a.SortEngine.setPrimaryKey(b)};this.removePrimaryKey=function(){return a.SortEngine.removePrimaryKey()}; | ||
this.setDefaultSort=function(){return a.SortEngine.setDefaultSort()};this.sortBy=function(b){return a.SortEngine.sortBy(b)};this.sortData=function(){return a.SortEngine.sortData()};this.reverseData=function(){return a.SortEngine.reverseData()};this.getData=function(){return a.FilterEngine.FilteredData}}var G=Object.freeze({default:F,FilterValue:t,Filter:D,Sort:y}),H=G&&F||G;module.exports=H.default?H.default:H; | ||
'use strict';var e=require("data-filter"),g=require("data-sort"),h=require("filter-value"),k=function(){function a(b,a){for(var c=0;c<a.length;c++){var d=a[c];d.enumerable=d.enumerable||!1;d.configurable=!0;"value"in d&&(d.writable=!0);Object.defineProperty(b,d.key,d)}}return function(b,f,c){f&&a(b.prototype,f);c&&a(b,c);return b}}(),m=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,f=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=2<arguments.length&& | ||
void 0!==arguments[2]?arguments[2]:null;if(!(this instanceof a))throw new TypeError("Cannot call a class as a function");l.call(this);this.filterEngine=new e(b,new g(b,f,c))}k(a,[{key:"FilterEngine",get:function(){return this.filterEngine}},{key:"SortEngine",get:function(){return this.filterEngine.SortEngine}},{key:"Data",get:function(){return this.getData()}}]);return a}();m.Filter=e;m.Sort=g;m.FilterValue=h; | ||
function l(){var a=this;this.setData=function(b){return a.FilterEngine.setData(b)};this.updateFilters=function(){var b;return(b=a.FilterEngine).update.apply(b,arguments)};this.removeFilters=function(){var b;return(b=a.FilterEngine).removeFilters.apply(b,arguments)};this.clearFilters=function(){return a.FilterEngine.clearFilters()};this.setSortFunction=function(b){return a.SortEngine.setSortFunction(b)};this.setPrimaryKey=function(b){return a.SortEngine.setPrimaryKey(b)};this.removePrimaryKey=function(){return a.SortEngine.removePrimaryKey()}; | ||
this.setDefaultSort=function(){return a.SortEngine.setDefaultSort()};this.sortBy=function(b){return a.SortEngine.sortBy(b)};this.sortData=function(){return a.SortEngine.sortData()};this.reverseData=function(){return a.SortEngine.reverseData()};this.getData=function(){return a.FilterEngine.FilteredData}}var n=Object.freeze({default:m,FilterValue:h,Filter:e,Sort:g}),p=n&&m||n;module.exports=p.default?p.default:p; |
{ | ||
"name": "data-engine", | ||
"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": [ | ||
@@ -50,5 +50,5 @@ "Data", | ||
"loose-envify": "^1.1.0", | ||
"filter-value": "^2.0.0-rc.8", | ||
"data-filter": "^2.0.0-rc.8", | ||
"data-sort": "^2.0.0-rc.8" | ||
"filter-value": "^2.0.0-rc.9", | ||
"data-filter": "^2.0.0-rc.9", | ||
"data-sort": "^2.0.0-rc.9" | ||
}, | ||
@@ -55,0 +55,0 @@ "browserify": { |
@@ -1,2 +0,2 @@ | ||
/** @license Engine v2.0.0-rc.8 | ||
/** @license Engine v2.0.0-rc.9 | ||
* data-engine.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-engine.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
55657
1298
3
2
Updateddata-filter@^2.0.0-rc.9
Updateddata-sort@^2.0.0-rc.9
Updatedfilter-value@^2.0.0-rc.9