Skip to content

Commit 2929b6d

Browse files
Merge pull request #101 from maroshluskasc/u/mhluska/support-lists
Support lists
2 parents 154dbed + 1d7ade7 commit 2929b6d

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ Define the value of the input.
9797

9898
Return a function which can be used to filter an array. `keys` can be `String`, `[String]` or `null`.
9999

100-
If an array `keys` is an array, the function will return true if at least one of the keys of the item matches the serch term.
100+
If an array `keys` is an array, the function will return true if at least one of the keys of the item matches the search term.
101101

102102
### Static Methods
103103

104104
##### filter(searchTerm, [keys], [{caseSensitive, fuzzy, sortResults}])
105105

106106
Return a function which can be used to filter an array. `searchTerm` can be a `regex` or a `String`. `keys` can be `String`, `[String]` or `null`.
107107

108-
If an array `keys` is an array, the function will return true if at least one of the keys of the item matches the serch term.
108+
If an array `keys` is an array, the function will return true if at least one of the keys of the item matches the search term.
109109

110110
## Styles
111111

src/util.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import Fuse from 'fuse.js'
22

3+
function flatten (array) {
4+
return array.reduce((flat, toFlatten) => (
5+
flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten)
6+
), [])
7+
}
8+
39
export function getValuesForKey (key, item) {
410
const keys = key.split('.')
511
let results = [item]
612
keys.forEach(_key => {
7-
const tmp = []
13+
let tmp = []
814
results.forEach(result => {
915
if (result) {
1016
if (result instanceof Array) {
@@ -26,6 +32,10 @@ export function getValuesForKey (key, item) {
2632
results = tmp
2733
})
2834

35+
// Support arrays and Immutable lists.
36+
results = results.map(r => (r && r.push && r.toArray) ? r.toArray() : r)
37+
results = flatten(results)
38+
2939
return results.filter(r => typeof r === 'string' || typeof r === 'number')
3040
}
3141

0 commit comments

Comments
 (0)