Skip to content

Commit

Permalink
fix: value fetched at the end must be a string
Browse files Browse the repository at this point in the history
Closes #661
  • Loading branch information
krisk committed May 11, 2022
1 parent 18df773 commit 1de1dff
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/fuse.basic.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ var FuseIndex = /*#__PURE__*/function () {

record.$[keyIndex] = subRecords;
})();
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
var subRecord = {
v: value,
n: _this3.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class FuseIndex {
} else ;
}
record.$[keyIndex] = subRecords;
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
let subRecord = {
v: value,
n: this.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@

record.$[keyIndex] = subRecords;
})();
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
var subRecord = {
v: value,
n: _this3.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ var FuseIndex = /*#__PURE__*/function () {

record.$[keyIndex] = subRecords;
})();
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
var subRecord = {
v: value,
n: _this3.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class FuseIndex {
} else ;
}
record.$[keyIndex] = subRecords;
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
let subRecord = {
v: value,
n: this.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@

record.$[keyIndex] = subRecords;
})();
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
var subRecord = {
v: value,
n: _this3.norm.get(value)
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/tools/FuseIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class FuseIndex {
}
}
record.$[keyIndex] = subRecords
} else if (!isBlank(value)) {
} else if (isString(value) && !isBlank(value)) {
let subRecord = {
v: value,
n: this.norm.get(value)
Expand Down
17 changes: 12 additions & 5 deletions test/fuzzy-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ describe('Recurse into arrays', () => {
})
})


describe('Recurse into objects in arrays with null object in array', () => {
const customBookList = [
{
Expand Down Expand Up @@ -381,7 +380,7 @@ describe('Recurse into objects in arrays with null object in array', () => {
{
value: 'British'
},
null,
null
]
}
}
Expand All @@ -401,13 +400,12 @@ describe('Recurse into objects in arrays with null object in array', () => {
expect(result).toHaveLength(1)
})

test('whose value is the ISBN of the book', () => {
test('whose value is the ISBN of the book', () => {
expect(result[0].item.ISBN).toBe('0321784421')
})
})
})


describe('Recurse into objects in arrays', () => {
const customBookList = [
{
Expand Down Expand Up @@ -1193,12 +1191,21 @@ describe('Standard dotted keys', () => {
})

describe('Breaking values', () => {
test('Non-strings are still processed', () => {
test('Booleans are still processed', () => {
const data = [{ first: false }]
const options = { keys: [{ name: 'first' }] }
const fuse = new Fuse(data, options)

const result = fuse.search('fa')
expect(result).toHaveLength(1)
})

test('Object values are ignored', () => {
const data = [{ a: 'hello' }, { a: {} }]
const options = { keys: ['a'] }
const fuse = new Fuse(data, options)

const result = fuse.search('hello')
expect(result).toHaveLength(1)
})
})

0 comments on commit 1de1dff

Please sign in to comment.