match-sorter
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -70,7 +70,7 @@ (function (global, factory) { | ||
} | ||
return keys.reduce(function (_ref2, key, i) { | ||
var valuesToRank = getAllValuesToRank(item, keys); | ||
return valuesToRank.reduce(function (_ref2, itemValue, i) { | ||
var rank = _ref2.rank; | ||
var keyIndex = _ref2.keyIndex; | ||
var itemValue = getItemValue(item, key); | ||
var newRank = getMatchRanking(itemValue, value); | ||
@@ -231,3 +231,15 @@ if (newRank > rank) { | ||
/** | ||
* Gets all the values for the given keys in the given item and returns an array of those values | ||
* @param {Object} item - the item from which the values will be retrieved | ||
* @param {Array} keys - the keys to use to retrieve the values | ||
* @return {Array} the values in an array | ||
*/ | ||
function getAllValuesToRank(item, keys) { | ||
return keys.reduce(function (allVals, key) { | ||
return allVals.concat(getItemValue(item, key)); | ||
}, []); | ||
} | ||
module.exports = exports.default; // CommonJS compat | ||
}); |
{ | ||
"name": "match-sorter", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -75,3 +75,11 @@ # match-sorter | ||
//this also works with **nested keys** | ||
// You can specify a key that is an array of values and the best match from that value is the one that's used for the ranking | ||
const iceCreamYum = [ | ||
{favoriteIceCream: ['mint', 'chocolate']}, | ||
{favoriteIceCream: ['candy cane', 'brownie']}, | ||
{favoriteIceCream: ['birthday cake', 'rocky road', 'strawberry']}, | ||
] | ||
matchSorter(iceCreamYum, 'cc', {keys: 'favoriteIceCream'}) // [{favoriteIceCream: ['candy cane', 'brownie']}, {favoriteIceCream: ['mint', 'chocolate']}] | ||
// this also works with **nested keys** | ||
const nestedObjList = [ | ||
@@ -78,0 +86,0 @@ {name: {first: 'Janice'}}, |
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
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
19567
215
172