Skip to content

Commit

Permalink
fix: if null in array
Browse files Browse the repository at this point in the history
  • Loading branch information
apellicc committed Oct 5, 2020
1 parent 7767e4f commit 740a500
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dist/fuse.basic.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ function get(obj, path) {
var arr = false;

var deepGet = function deepGet(obj, path, index) {
if (!isDefined(obj)) {
return;
}

if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
3 changes: 3 additions & 0 deletions dist/fuse.basic.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ function get(obj, path) {
let arr = false;

const deepGet = (obj, path, index) => {
if (!isDefined(obj)) {
return
}
if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.esm.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
var arr = false;

var deepGet = function deepGet(obj, path, index) {
if (!isDefined(obj)) {
return;
}

if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.basic.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ function get(obj, path) {
var arr = false;

var deepGet = function deepGet(obj, path, index) {
if (!isDefined(obj)) {
return;
}

if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
3 changes: 3 additions & 0 deletions dist/fuse.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ function get(obj, path) {
let arr = false;

const deepGet = (obj, path, index) => {
if (!isDefined(obj)) {
return
}
if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.esm.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@
var arr = false;

var deepGet = function deepGet(obj, path, index) {
if (!isDefined(obj)) {
return;
}

if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj);
Expand Down
2 changes: 1 addition & 1 deletion dist/fuse.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/helpers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default function get(obj, path) {
let arr = false

const deepGet = (obj, path, index) => {
if (!isDefined(obj)) {
return
}
if (!path[index]) {
// If there's no path left, we've arrived at the object we care about.
list.push(obj)
Expand Down
64 changes: 64 additions & 0 deletions test/fuzzy-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,70 @@ describe('Recurse into arrays', () => {
})
})


describe('Recurse into objects in arrays with null object in array', () => {
const customBookList = [
{
ISBN: '0765348276',
title: "Old Man's War",
author: {
name: 'John Scalzi',
tags: [
{
value: 'American'
},
null
]
}
},
{
ISBN: '0312696957',
title: 'The Lock Artist',
author: {
name: 'Steve Hamilton',
tags: [
{
value: 'American'
}
]
}
},
{
ISBN: '0321784421',
title: 'HTML5',
author: {
name: 'Remy Sharp',
tags: [
{
value: 'British'
},
null,
]
}
}
]
const customOptions = {
keys: ['author.tags.value'],
threshold: 0
}
let fuse
beforeEach(() => (fuse = setup(customBookList, customOptions)))

describe('When searching for the author tag "British"', () => {
let result
beforeEach(() => (result = fuse.search('British')))

test('we get a list containing exactly 1 item', () => {
expect(result).toHaveLength(1)
})

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

0 comments on commit 740a500

Please sign in to comment.