match-sorter
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -74,3 +74,4 @@ (function (global, factory) { | ||
var newRank = getMatchRanking(item[key], value); | ||
var itemValue = getItemValue(item, key); | ||
var newRank = getMatchRanking(itemValue, value); | ||
if (newRank > rank) { | ||
@@ -214,3 +215,19 @@ rank = newRank; | ||
/** | ||
* Gets value for key in item at arbitrarily nested keypath | ||
* @param {Object} item - the item | ||
* @param {Object} key - the potentially nested keypath | ||
* @return {String} - the value at nested keypath | ||
*/ | ||
function getItemValue(item, key) { | ||
var isNested = key.indexOf('.') !== -1; | ||
if (!isNested) { | ||
return item[key]; | ||
} | ||
return key.split('.').reduce(function (itemObj, nestedKey) { | ||
return itemObj[nestedKey]; | ||
}, item); | ||
} | ||
module.exports = exports.default; // CommonJS compat | ||
}); |
{ | ||
"name": "match-sorter", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Simple, expected, and deterministic best-match sorting of an array in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# match-sorter | ||
Simple, expected, and deterministic best-match sorting of an array in JavaScript | ||
Simple, expected, and deterministic best-match sorting of an array in JavaScript. **[Demo](https://jsbin.com/vewoka/edit?js,output)** | ||
@@ -12,3 +12,3 @@ [![Build Status][build-badge]][build] | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
@@ -113,4 +113,4 @@ [![Donate][donate-badge]][donate] | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) | | ||
| :---: | | ||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/match-sorter/commits?author=kentcdodds) | [<img src="https://avatars.githubusercontent.com/u/8263298?v=3" width="100px;"/><br /><sub>Conor Hastings</sub>](http://conorhastings.com)<br />[💻](https://github.com/kentcdodds/match-sorter/commits?author=conorhastings) | | ||
| :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
@@ -117,0 +117,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
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
18325
204