krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.36k stars 772 forks source link

Add type definitions for matches #304

Closed mattmazzola closed 4 years ago

mattmazzola commented 5 years ago

Previously matches had any type which wasn't helpful.

Example match when input is array of strings

      {
        "indices": [
          [
            1,
            1
          ],
          [
            3,
            3
          ],
          [
            6,
            12
          ]
        ],
        "value": "anotherString"
      }

Example match when input is objects:

      {
        "indices": [
          [
            1,
            1
          ],
          [
            3,
            3
          ],
          [
            6,
            12
          ]
        ],
        "value": "anotherString",
        "key": "name",
        "arrayIndex": 0
      }

Ideally the matches should be consistent, but until: https://github.com/krisk/Fuse/issues/287 this should at least type the value and indices as most people will only want the indices.

mattmazzola commented 5 years ago

Seems https://github.com/krisk/Fuse/pull/301 is duplicate and doesn't account for key or arrayIndex being optional/undefined