# haystack-search

> Search for approximate matches to a query

Latest version **6.0.1** (published 2021-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install haystack-search
pnpm add haystack-search
yarn add haystack-search
bun add haystack-search
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2021-01-28 |
| First published | 2018-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alexander Lyon |
| Maintainers | alexanderlyon |
| Keywords | haystack, search, fuzzy-search, levenshtein, needle, stemming |

## Links

- npm: https://www.npmjs.com/package/haystack-search
- Repository: https://github.com/AlexanderLyon/Haystack
- Homepage: https://github.com/AlexanderLyon/Haystack#readme
- Issues: https://github.com/AlexanderLyon/Haystack/issues
- npm.io page: https://npm.io/package/haystack-search

## Dependencies (1)

- [stemmer](https://npm.io/package/stemmer.md) ^1.0.5

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 6.0.1 (latest) — 2021-01-28
- 6.0.0 — 2021-01-28
- 5.0.0 — 2020-05-17
- 4.4.41 — 2019-04-20
- 4.4.4 — 2019-04-07
- 4.4.3 — 2019-01-18
- 4.4.2 — 2019-01-09
- 4.4.1 — 2019-01-08
- 4.4.0 — 2018-12-22
- 4.3.41 — 2018-12-20
- 4.3.4 — 2018-12-18
- 4.3.3 — 2018-10-24
- 4.3.2 — 2018-09-01
- 4.3.1 — 2018-07-16
- 4.3.0 — 2018-06-16
- … 5 more at https://npm.io/package/haystack-search/versions

## README

# Haystack

[![npm](https://img.shields.io/npm/v/haystack-search.svg?style=flat-square)](https://www.npmjs.com/package/haystack-search)
[![npm](https://img.shields.io/npm/dt/haystack-search.svg?style=flat-square)](https://www.npmjs.com/package/haystack-search)

## Overview

Haystack is a lightweight search / suggestion library that can be used to find similar matches to a word. Just provide the source data to search against (as an array or object), and Haystack will return a list of approximate matches. The lower the `flexibility` the more strict your matches will be.

## Installation

Using npm:

```shell
npm i haystack-search
```

Import Haystack into your project:

```javascript
import Haystack from 'haystack-search';
// or
const Haystack = require('haystack-search');
```

```javascript
const haystack = new Haystack(options);
```

## Options

| Option                        | Default | Description                                                                                                                                     |
| ----------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `flexibility` (_number_)      | 2       | "Fuzziness" of search. The lower the number, the more strict your matches will be. (If set to `0`, Haystack will only look for perfect matches) |
| `caseSensitive` (_boolean_)   | false   | Whether or not search is case sensitive                                                                                                         |
| `exclusions` (_array_)        | []      | An array of strings or regexes to ignore in query                                                                                               |
| `ignoreStopWords` (_boolean_) | false   | Ignore common stop words such as the, a, in, etc.                                                                                               |
| `stemming` (_boolean_)        | false   | Reduces tokens in a query to their base words using [stemmer](https://github.com/words/stemmer 'stemmer')                                       |

## Methods

```javascript
haystack.search(searchTerm, source, [limit]);
```

Returns an array of matches within your `flexibility` range. If no limit is given, the default number of results will be 1.

```javascript
haystack.tokenize(searchTerm, [delimiter]);
```

Returns an array of tokens. By default this splits on whitespaces, but you can define a custom delimiter to use instead.

## Contributions

Contributions and suggestions for improvement are always welcome!

1. Fork this repo (<https://github.com/AlexanderLyon/Haystack/fork>)
2. Create your new feature branch
3. Commit changes and push
4. Create a new Pull Request

## License

[MIT](https://github.com/AlexanderLyon/Haystack/blob/master/LICENSE 'MIT License')

---
_Source: https://npm.io/package/haystack-search · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
