# @neosh11/autocomplete-search

> This package enables you to perform prefix searches with exceptional speed.

Latest version **1.0.0** (published 2023-03-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @neosh11/autocomplete-search
pnpm add @neosh11/autocomplete-search
yarn add @neosh11/autocomplete-search
bun add @neosh11/autocomplete-search
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-03-25 |
| First published | 2023-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Neosh |
| Maintainers | neosh11 |
| Keywords | autocomplete, search |

## Links

- npm: https://www.npmjs.com/package/@neosh11/autocomplete-search
- Repository: https://github.com/neosh11/npm-autocomplete
- Homepage: https://github.com/neosh11/npm-autocomplete#readme
- Issues: https://github.com/neosh11/npm-autocomplete/issues
- npm.io page: https://npm.io/package/@neosh11/autocomplete-search

## 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

- 1.0.0 (latest) — 2023-03-25
- 0.0.8 — 2023-03-23
- 0.0.7 — 2023-03-23
- 0.0.6 — 2023-03-23
- 0.0.5 — 2023-03-22
- 0.0.3 — 2023-03-22
- 0.0.2 — 2023-03-22
- 0.0.1 — 2023-03-22

## README

# npm-autocomplete

<p>
<img src="https://img.shields.io/pypi/wheel/pip?color=green&label=es6"/>
<img src="https://img.shields.io/pypi/wheel/pip?color=green&label=React"/>
<img src="https://img.shields.io/pypi/wheel/pip?color=green&label=React-Native"/>

<img src="https://img.shields.io/bundlephobia/min/@neosh11/autocomplete-search/1.0.0"/>
<img src="https://img.shields.io/bundlephobia/minzip/@neosh11/autocomplete-search/1.0.0"/>

<img src="https://img.shields.io/npm/v/@neosh11/autocomplete-search"/>

<img src="https://img.shields.io/twitter/follow/IGrowNeo?style=social"/>

</p>

## Overview

### If you use react -> here is a package that could handle everything for you => [Link](https://www.npmjs.com/package/autocomplete-search-react)

This TypeScript module provides a simple implementation of an auto-complete search using a trie data structure. It supports searching for words with a given prefix and inserting words with associated IDs into the trie. The module also provides an option for case-insensitive search

| Function                                       | Time                                                                      |
| ---------------------------------------------- | ------------------------------------------------------------------------- |
| `insert(word: string, id: string)`             | `O(m)`, where m is the length of the word being inserted.                 |
| `findWords(prefix: string, maxCount?: number)` | `O(k + n)`, where n is the number of nodes, k is the lenght of the prefix |

## Why use this and not a simple filter?

We tested out a simple filter on 100,000 tokens on the browser and these were the results:

| Method             | Time (ms) |
| ------------------ | --------- |
| Simple filter      | 467       |
| autoCompleteSearch | 4         |

If you want your results to instantly load as you're typing with a lot of data, this library will be a life saver!

## Usage

### install

```
# if using yarn
yarn add @neosh11/autocomplete-search

# if using npm
npm install @neosh11/autocomplete-search
```

## AutoCompleteSearch

### Importing the module

```ts
import { AutoCompleteSearch } from '@neosh11/autocomplete-search';
```

### Initializing the AutoCompleteSearch

To create an instance of `AutoCompleteSearch`, use the constructor and pass an optional `SearchOptions` object:

```ts
const searchOptions = { ignoreCase: true };
const autoCompleteSearch = new AutoCompleteSearch(searchOptions);
```

The `ignoreCase` option, if set to `true`, will perform case-insensitive search and insertions.

### Inserting words

To insert words into the trie, use the `insert` method:

```ts
autoCompleteSearch.insert('example', 'id123');
```

This inserts the word "example" with the associated ID "id123" into the trie.

### Searching for words

To search for words with a given prefix, use the `findWords` method:

```ts
const results = autoCompleteSearch.findWords('exa', 5);
```

This searches for words with the prefix "exa" and returns up to 5 associated IDs in an array.

By default, the maximum number of ids returned is 100

## String2ObjectAutoCompleteSearch

### Importing the module

```ts
import { String2ObjectAutoCompleteSearch } from '@neosh11/autocomplete-search';
```

### Initializing the AutoCompleteSearch

To create an instance of `AutoCompleteSearch`, use the constructor and pass an optional `SearchOptions` object:

```ts
const searchOptions = {
  ignoreCase: true,
  objectIdProperty: 'id',
  tokenizer: ' ',
};
const autoCompleteSearch = new AutoCompleteSearch(searchOptions);
```

The `ignoreCase` option, if set to `true`, will perform case-insensitive search and insertions.

The `objectIdProperty` option will examine which property to use as a unique ID

The `tokenizer` option, if used will tokenize the search string

### Inserting words

To insert words into the trie, use the `insert` method:

```ts
autoCompleteSearch.insert('example', object);
```

This inserts the `object` with the word 'example'.

### Searching for words

To search for words with a given prefix, use the `findWords` method:

```ts
const results = autoCompleteSearch.findObjects('exa', 5);
```

This searches for words with the prefix "exa" and returns up to 5 associated objects which match this description.

By default, the maximum number of ids returned is 100

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