Skip to content

Commit 64815b3

Browse files
Merge branch 'master' into u/mhluska/support-lists
2 parents 32196e9 + 154dbed commit 64815b3

14 files changed

Lines changed: 162 additions & 70 deletions

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2

.eslintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ example/lib
66
example/app.bundle.js
77
/lib
88
coverage
9+
.vscode/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ language: node_js
22
node_js:
33
- "4"
44
- "5"
5+
- "6"

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ build:
88
clean:
99
rm -rf lib && rm -rf example/lib && rm -f example/app.bundle.js
1010

11-
lint:
12-
$(BIN)/eslint src && $(BIN)/eslint tests
13-
14-
PHONY: build clean lint
11+
PHONY: build clean

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ Define if the search should be case sensitive. Default is `false`
8383

8484
Define if the search should be fuzzy. Default is `false`
8585

86+
##### sortResults
87+
88+
Define if search results should be sorted by relevance (only works with fuzzy search). Default is `false`
89+
8690
##### value
8791

8892
Define the value of the input.
@@ -97,7 +101,7 @@ If an array `keys` is an array, the function will return true if at least one of
97101

98102
### Static Methods
99103

100-
##### filter(searchTerm, [keys], [caseSensitive])
104+
##### filter(searchTerm, [keys], [{caseSensitive, fuzzy, sortResults}])
101105

102106
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`.
103107

example/src/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const App = React.createClass({
1717

1818
return (
1919
<div>
20-
<SearchInput className="search-input" onChange={this.searchUpdated} />
20+
<SearchInput className='search-input' onChange={this.searchUpdated} />
2121
{filteredEmails.map(email => {
2222
return (
23-
<div className="mail" key={email.id}>
24-
<div className="from">{email.user.name}</div>
25-
<div className="subject">{email.subject}</div>
23+
<div className='mail' key={email.id}>
24+
<div className='from'>{email.user.name}</div>
25+
<div className='subject'>{email.subject}</div>
2626
</div>
2727
)
2828
})}

package.json

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-search-input",
3-
"version": "0.10.4",
3+
"version": "0.11.1",
44
"description": "Simple react.js component for a search input, providing a filter function.",
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
@@ -9,28 +9,20 @@
99
"src"
1010
],
1111
"devDependencies": {
12-
"babel": "^6.5.2",
1312
"babel-cli": "^6.8.0",
14-
"babel-core": "^6.7.6",
15-
"babel-eslint": "^6.0.2",
16-
"babel-polyfill": "^6.7.4",
13+
"babel-jest": "^19.0.0",
1714
"babel-preset-es2015": "^6.6.0",
1815
"babel-preset-react": "^6.5.0",
1916
"babel-preset-stage-0": "^6.5.0",
20-
"babel-register": "^6.7.2",
21-
"chai": "^3.5.0",
22-
"chai-as-promised": "^5.3.0",
23-
"eslint": "^3.3.0",
24-
"eslint-config-standard": "^5.1.0",
25-
"eslint-plugin-promise": "^2.0.1",
26-
"eslint-plugin-standard": "^2.0.0",
27-
"mocha": "^3.0.2",
17+
"immutable": "^3.8.1",
18+
"jest": "^19.0.2",
2819
"react": "^15.1.0",
2920
"react-dom": "^15.1.0",
30-
"sinon": "^1.17.3",
31-
"webpack": "^1.12.15"
21+
"standard": "^10.0.2",
22+
"webpack": "^2.2.1"
3223
},
3324
"scripts": {
25+
"test": "standard && jest",
3426
"prepublish": "make clean build"
3527
},
3628
"repository": {
@@ -46,13 +38,15 @@
4638
"javascript",
4739
"react-component"
4840
],
49-
"author": "Mathieu Dutour",
41+
"author": "Mathieu Dutour <mathieu@dutour.me>",
5042
"license": "MIT",
5143
"bugs": {
5244
"url": "https://github.com/enkidevs/react-search-input/issues"
5345
},
5446
"homepage": "https://github.com/enkidevs/react-search-input",
5547
"dependencies": {
56-
"fuse.js": "^2.2.0"
48+
"fuse.js": "^3.0.0",
49+
"prop-types": "^15.5.8",
50+
"create-react-class": "^15.5.2"
5751
}
5852
}

react-search-input.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
}
66

77
.search-input::before {
8-
content: "\26b2";
8+
content: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAQJJREFUKBWVkr2uQUEUhf3ET6GRaC5aFRoJKrf1BKpb8SwqovYGXkCj00k0QnRKEYkILYobvpUYmeMMyVnJl7P3mjN7Zu9zwiGv2qRFyMMSRrAFp6JPN8XzBj+wgDkUYAg7WINTYdwpDECxrRLJHeq2accdkgm8bzTvNAg2EDOGeUYI1KNO1gkuzTA1g8T7ojbn4ONQWPuHPWgeHmnzCqoe15tkSNPgPEAn68oVcOmA2XMtGK9FoE/VhOTTVNExqLCGZnxCv2pYauEC6lF0oQxX6IOvb7yX9NPEQafan+aPXDdQC18LsO6Tip5BBY6gIQaSbnMCFRCBZRcIvFkbsvCr4AFGOCxQy+JdGQAAAABJRU5ErkJggg==');
99
display: block;
1010
position: absolute;
1111
width: 15px;
1212
z-index: 3;
1313
height: 15px;
14-
transform: rotate(-45deg);
1514
font-size: 20px;
1615
top: 11px;
17-
left: 13px;
16+
left: 16px;
1817
line-height: 32px;
18+
opacity: 0.6;
1919
}
2020

2121
.search-input > input {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* globals test expect */
2+
import { Map } from 'immutable'
3+
import { getValuesForKey } from '../util'
4+
5+
test('should get the values to search on in an object', () => {
6+
const value = getValuesForKey('foo', {
7+
foo: 'bar'
8+
})
9+
expect(value).toEqual(['bar'])
10+
})
11+
12+
test('should get the values to search on in an array', () => {
13+
const value = getValuesForKey('foo', [{
14+
foo: 'bar'
15+
}])
16+
expect(value).toEqual(['bar'])
17+
})
18+
19+
test('should get the values to search on in a nested object', () => {
20+
const value = getValuesForKey('foo.bar', {
21+
foo: {
22+
bar: 'baz'
23+
}
24+
})
25+
expect(value).toEqual(['baz'])
26+
})
27+
28+
test('should get the values to search on in a nested array', () => {
29+
const value = getValuesForKey('foo', {
30+
foo: ['bar', 'baz']
31+
})
32+
expect(value).toEqual(['bar', 'baz'])
33+
})
34+
35+
test('should get the values to search on in a nested array', () => {
36+
const value = getValuesForKey('foo.bar', {
37+
foo: [{
38+
bar: 'baz'
39+
}, {
40+
bar: 'baz2'
41+
}]
42+
})
43+
expect(value).toEqual(['baz', 'baz2'])
44+
})
45+
46+
test('should get the values to search on in a nested array with an index', () => {
47+
const value = getValuesForKey('foo.1.bar', {
48+
foo: [{
49+
bar: 'baz'
50+
}, {
51+
bar: 'baz2'
52+
}]
53+
})
54+
expect(value).toEqual(['baz2'])
55+
})
56+
57+
test('should ignore undefined values', () => {
58+
const value = getValuesForKey('fooz', {
59+
foo: [{
60+
bar: 'baz'
61+
}, {
62+
bar: 'baz2'
63+
}]
64+
})
65+
expect(value).toEqual([])
66+
})
67+
68+
test('should get the values to search on in an immutable map', () => {
69+
const value = getValuesForKey('foo.bar', Map({
70+
foo: {
71+
bar: 'baz'
72+
}
73+
}))
74+
expect(value).toEqual(['baz'])
75+
})
76+
77+
test('should ignore non-string and non-number values', () => {
78+
const value = getValuesForKey('foo.bar', {
79+
foo: [{
80+
bar: []
81+
}, {
82+
bar: []
83+
}]
84+
})
85+
expect(value).toEqual([])
86+
})

0 commit comments

Comments
 (0)