Comparing version 1.0.5 to 1.0.6
'use strict'; | ||
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 _Helper = require('./Helper'); | ||
@@ -18,2 +20,13 @@ | ||
}; | ||
} | ||
if (!Array.prototype.objFilter) { | ||
Array.prototype.objFilter = function (searchable) { | ||
var keyInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '['; | ||
var keyEnd = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ']'; | ||
var separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '|'; | ||
var strict = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
if (_typeof(this) !== 'object') return _Helper2.default.filterObjectsCollectionBykey(this, searchable, keyInit, keyEnd, separator, strict); | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -17,3 +17,3 @@ Object.defineProperty(exports, "__esModule", { | ||
_createClass(Helper, [{ | ||
key: "sort", | ||
key: 'sort', | ||
@@ -49,3 +49,3 @@ /*** | ||
}, { | ||
key: "cleanEmpties", | ||
key: 'cleanEmpties', | ||
value: function cleanEmpties(array) { | ||
@@ -58,2 +58,82 @@ var strict = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
} | ||
/** | ||
* Magic search for matching values in collection objects. | ||
* | ||
* It can handle a single or multiple search for each key. | ||
* Accepts Two methods: | ||
* strict mode (exact matching) | ||
* Soft mode (matching the substring) | ||
* | ||
* By default "soft mode" | ||
* E.g => [keyA]term1|term2[keyB]term1|term2[keyC]singleTerm | ||
* | ||
* @param {Array} collection Objects collection. | ||
* @param searchable | ||
* @param keyInit | ||
* @param keyEnd | ||
* @param separator | ||
* @param strict | ||
* @return Array | ||
*/ | ||
}, { | ||
key: 'filterObjectsCollectionBykey', | ||
value: function filterObjectsCollectionBykey(collection, searchable) { | ||
var keyInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '['; | ||
var keyEnd = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ']'; | ||
var separator = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '|'; | ||
var strict = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; | ||
//get a collection of key and values to search. | ||
var groupedByTerm = searchable.split(keyInit); | ||
groupedByTerm.clean().forEach(function (searchable) { | ||
//get the key name | ||
var pos = searchable.indexOf(keyEnd); | ||
var key = searchable.substr(0, pos); | ||
//text to search | ||
var text = searchable.substr(pos + 1, searchable.length); | ||
//Check for multiple or single search values. | ||
if (text.indexOf(separator) !== -1) { | ||
//Create array with the searched texts. | ||
var texts = text.split(separator); | ||
collection = collection.filter(function (item) { | ||
var found = false; | ||
texts.forEach(function (text) { | ||
if (strict) { | ||
if (_.toUpper(item[key]) === _.toUpper(text)) found = true; | ||
} else { | ||
if (_.toUpper(item[key]).indexOf(_.toUpper(text)) !== -1) { | ||
found = true; | ||
} | ||
} | ||
}); | ||
return found; | ||
}); | ||
// Single search text. | ||
} else { | ||
collection = collection.filter(function (item) { | ||
if (strict) { | ||
if (_.toUpper(item[key]) === _.toUpper(text)) return true; | ||
} else { | ||
if (_.toUpper(item[key]).indexOf(_.toUpper(text)) !== -1) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
}); | ||
return collection; | ||
} | ||
}]); | ||
@@ -60,0 +140,0 @@ |
{ | ||
"name": "psl-core", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Core Library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
47738
17
244
1