question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

value.trim() in not function at types.js:40

See original GitHub issue

Describe the bug

A clear and concise description of what the bug is.

Non-number/string value is allowed through helper/get.js causes runtime error value.trim() is not a function at https://github.com/krisk/Fuse/blob/a2d62fb6b1ad4cb71c485632df4670baf6f32a6a/src/helpers/types.js#L40

Error:

node_modules/fuse.js/dist/fuse.common.js:242
  return !value.trim().length;
                ^

TypeError: value.trim is not a function

Version

The Fuse.js version where this bug is happening.

6.3.0 and above

Is this a regression?

Yes, the previous version in which this bug was not present was: ...

Yes, version below 6.3.0 Bug seem to have been introduced by https://github.com/krisk/Fuse/commit/938db2aebb1a5b2d610cd8bb3258ff701baa46fb

🔬Minimal Reproduction

const Fuse = require('fuse.js')

const data = [{first: false}]
const options = {keys: [{name: 'first'}]}
const fuse = new Fuse(data, options)

fuse.search('a')

Additional context

else if below is always true https://github.com/krisk/Fuse/blob/90f153793432997654a2a006e0f01753cd23c9ff/src/helpers/get.js#L28

since line below returns an array with at least one item https://github.com/krisk/Fuse/blob/90f153793432997654a2a006e0f01753cd23c9ff/src/tools/KeyStore.js#L74

Which leads into another deepGet with obj = false which leads to if block below and pushing non-string/number value into list https://github.com/krisk/Fuse/blob/90f153793432997654a2a006e0f01753cd23c9ff/src/helpers/get.js#L9

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
joaobibianocommented, Nov 5, 2020

I’m having this problem when the lib try read a instance of Date… someone knows how to fix?

3reactions
Techn1xcommented, Sep 3, 2020

Hi @krisk , I just upgraded to 6.4.1 and seem to encounter this error.

Screenshot from 2020-09-03 12-31-49

Screenshot from 2020-09-03 12-32-11

My items look like;

[
  { value: 'placement lesson' },
  {
    value: {
      grade: 1,
      lessonNumber: "1",
      name: "Lesson 1",
    },
  },
]

My options look like;

{
  threshold: 0.3,
  ignoreLocation: true,
  keys: ['value', 'value.name', 'value.lessonNumber'],
}

value is included in the keys list because sometimes in our data, value is a string, other times it’s an object.

Downgrading to < 6.3.0 does fix the issue for now. Is my usage a supported use-case or do I need to refactor my code?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: trim is not a function in JavaScript | bobbyhadz
The "trim is not a function" error occurs when we call the trim() method on a value that is not a string. To...
Read more >
javascript - .trim() is not a function - Stack Overflow
If you splitted your string into an array you can call the map function and trim each value in your newly created array....
Read more >
[Solved] TypeError: trim is not a function - ItsJavaScript
The TypeError: trim is not a function occurs if we call a trim() method on the value that is not of a type...
Read more >
String.prototype.trim() - JavaScript - MDN Web Docs
The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string.
Read more >
value.trim() in not function at types.js:40 - Krisk/Fuse - Codesti
A clear and concise description of what the bug is. Non-number/string value is allowed through helper/get.js causes runtime error value.trim() is not a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found