deitch/searchjs

Search returns undefined in version 1.0.1

hewrin opened this issue · 6 comments

Hi

When I was using version 0.8, if I did

import { Search } from 'searchjs'

It would work.

But in version 1.0.1

Doing this will give me a Search value of undefined.

Not sure what other info I will need to give youto help debug this. But let me know and I'll be happy to help.

Thanks for the great library!

How are you running it?

I don't see an export named Search. In CJS mode, you can do:

s = require('searchjs')
{ setDefaults: [Function: setDefaults],
  resetDefaults: [Function: resetDefaults],
  singleMatch: [Function: singleMatch],
  matchArray: [Function: matchArray],
  matchObject: [Function: matchObject] }

In es6 mode, you need the explicit exports:

> import { singleMatch, matchArray } from 'searchjs'
undefined
> singleMatch
[Function: singleMatch]

We probably should update the README to show how to use with es6 modules.

How did you use it before with import { Search } from 'searchjs' ?

Thanks for the reply

I pretty much just did

import Search from 'searchjs'

Search.matchArray(data, { 'attributes': attribute})

It is interesting that you were able to do so before. It might have been an unintended artifact of how it was structured (one of those "unpublished APIs" :-) ).

Let's turn this around. You did import Search, and you had all of the things I can get via import { ... }, specifically:

  • matchObject
  • matchArray
  • matchField

Correct? No reason we cannot add an export default here.

Actually, the more I think about it, the less it makes sense to me to do so, as it kind of goes against the es6 modules grain. Any reason not to do:

import {matchField, matchObject} from 'searchjs'

?

So sorry for the late reply, yes doing it like that works as well.

Great. Going to close out the issue then. Use it well!