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

match-sorter

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-sorter - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

16

dist/index.js

@@ -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
});

2

package.json
{
"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'}},

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