# sugg

> Sugg debounces the input, load and caches the results, and emit `result` events when there is new results.

Latest version **0.0.2** (published 2015-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install sugg
pnpm add sugg
yarn add sugg
bun add sugg
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-12-03 |
| First published | 2014-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Christian Tellnes |
| Maintainers | tellnes |
| Keywords | suggest, suggestion, debounce, cache |

## Links

- npm: https://www.npmjs.com/package/sugg
- Repository: https://github.com/tellnes/sugg
- Issues: https://github.com/tellnes/sugg/issues
- npm.io page: https://npm.io/package/sugg

## Dependencies (2)

- [inherits](https://npm.io/package/inherits.md) ~2.0.1
- [async-cache](https://npm.io/package/async-cache.md) ~1.0.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2015-12-03
- 0.0.1 — 2014-07-26

## README

# Sugg

[![Version npm](https://img.shields.io/npm/v/sugg.svg?style=flat-square)](https://www.npmjs.com/package/sugg)[![npm Downloads](https://img.shields.io/npm/dm/sugg.svg?style=flat-square)](https://www.npmjs.com/package/sugg)[![Build Status](https://img.shields.io/travis/tellnes/sugg/master.svg?style=flat-square)](https://travis-ci.org/tellnes/sugg)[![Dependencies](https://img.shields.io/david/tellnes/sugg.svg?style=flat-square)](https://david-dm.org/tellnes/sugg)[![Tips](http://img.shields.io/gratipay/tellnes.png?style=flat-square)](https://gratipay.com/~tellnes/)

Sugg debounces the input, load and caches the results, and emit `result` events when there is
new results.

## Example

```js
var Sugg = require('sugg')

var sugg = new Sugg({ wait: 300, load: load })
function load(query, cb) {
  setTimeout(function () {
    cb(null, 'results for ' + query)
  }, 200)
}

sugg.on('wait', function () {
  console.log('wait')
})

sugg.on('idle', function () {
  console.log('idle')
})

sugg.on('result', function (result) {
  console.log(result) // outputs `results for hello world` after 500ms (300 + 200)
})

sugg.update('hello world')
```

## Usage

```js
var Sugg = require('sugg')

var sugg = new Sugg({ wait: 200, load: load, maxAge: 1000*60*5, max: 100 })
function load(query, cb) {
  $.ajax(
      { url: 'http://localhost:9200/_suggest'
      , data: JSON.stringify(
        { 'suggestion':
          { 'text': query
          , 'completion':
            { 'field': 'suggest'
            }
          }
        })
      , dataType: 'json'
      , error: function (xhr, status, err) {
          cb(err)
        }
      , success: function (data) {
          cb(null, data)
        }
      }
    )
}

sugg.on('wait', function () {
  // show loader
})

sugg.on('idle', function () {
  // hide loader
})

sugg.on('result', function (suggestions) {
  // update suggestions html
})

sugg.on('error', function (err) {
  // handle error
})
```

## Options

- `wait` Number of milliseconds to wait for following update before executing
  the load function. Defaults to `300`

- `load` Method to load results if it's not in the cache.
 Please see
  [async-cache](https://www.npmjs.org/package/async-cache)
  for details.

- `max` The maximum size of the cache. Defaults to `Infinity`.

- `maxAge` Maximum age in ms. Items are not pro-actively pruned out as they age,
  but if you try to get a result that is too old, it'll drop it and reload it
  before giving it to you.

The options object is passed directly to the underlying cache object, so all options for
[async-cache](https://www.npmjs.org/package/async-cache)
and
[lru-cache](https://www.npmjs.org/package/lru-cache)
is also available.


## Install

    npm install sugg

## License

MIT

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