# memee

> Javascript package for memoizing functions. Returning directly the result of function if it was called with the same arguments avoiding it's redundant work.

Latest version **1.1.15** (published 2018-07-06) · MIT license · 0 weekly downloads

## Install

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

## 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 | 1.1.15 |
| Published | 2018-07-06 |
| First published | 2018-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Hicham NAIMI |
| Maintainers | hichamnaimi |
| Keywords | javascript, memoizing, debounce, javascript-debounce-function, javascript-memoize-function, functions, javascript-functions, javascript-cache-function, cache, javascript-performance-function, javascript-optimize-function, optimize, memee, memorize-javascript-function |

## Links

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

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

- 1.1.15 (latest) — 2018-07-06
- 1.1.14 — 2018-07-06
- 1.1.13 — 2018-04-19
- 1.1.12 — 2018-04-18
- 1.1.11 — 2018-04-18
- 1.1.10 — 2018-04-18
- 1.1.9 — 2018-04-18
- 1.1.8 — 2018-04-18
- 1.1.7 — 2018-04-18
- 1.1.6 — 2018-04-18
- 1.1.5 — 2018-04-17
- 1.1.4 — 2018-04-17
- 1.1.3 — 2018-04-17
- 1.1.2 — 2018-04-17
- 1.1.1 — 2018-04-16
- … 16 more at https://npm.io/package/memee/versions

## README

# Memee

Javascript package with **0 dependencies** for memoizing and debouncing functions. Returning directly the result of function if it was called with the same arguments avoiding it's redundant work.

### Installing
Using npm:

```
$ npm install memee
```

Using yarn:

```
$ yarn add memee
```

###Using memee

Import the package into the project
```javascript
const memee = require("memee");
```

Always caching the function until we close the application.
```javascript
let iterator = 0;
const increment = () => ++iterator;

const memoizedIncrement = memee(increment);

const firstCallResult = memoizedIncrement(); // 1
const secondCallResult = memoizedIncrement(); // 1
```

### Maximum age for memoization
*{maxAge} option* Define the duration of memoization.

```javascript
const increment = () => ++iterator;

const memoizedIncrement = memee(increment, { maxAge: 3000 });

const firstCallResult = memoizedIncrement(); // 1
const secondCallResult = memoizedIncrement(); // 1

// After 3seconds the cache is expired
const thirdCallResult = memoizedIncrement(); // 2
```

### Memoizing promises
memee can also memoize promises.
```javascript
let iterator = 0;

const incrementPromise = () => {
  ++iterator;
  return Promise.resolve(iterator);
}

const memoizedIncrementPromise = memee(incrementPromise);

// First call
memoizedIncrementPromise().then(resultA => {
  console.log(resultA); // 1

  // Second call
  memoizedIncrementPromise().then(resultB => {
    console.log(resultB); // 1
  });
});
```

### Define debounced function without memoization
Delay the execution of function for a giving time.
```javascript
let iterator = 0;
const increment = () => ++iterator;

// Callback holding increment result
const incrementResult = (result) => console.log(result); 

const delayedIncrement = memee(increment, {}, { debounced: true, wait: 2000, result: incrementResult });

// The callback is called with 2s delay: incrementResult(1)
delayedIncrement();
```

### Define debounced and memoized function
```javascript
let iterator = 0;
const increment = () => ++iterator;

// Callback holding increment result
const incrementResult = (result) => console.log(result); 

const memDelayedIncrement = memee(increment, { maxAge: 6000 },{ debounced: true, wait: 2000, result: incrementResult });

// The callback is called with 2s delay: incrementResult(1)
memDelayedIncrement();
// The callback is called with 2s delay: incrementResult(1)
memDelayedIncrement();

// After 6s the callback is called with 2s of delay: incrementResult(2)
setTimeout(memDelayedIncrement, 7000);
```

## Versioning

We use [SemVer](http://semver.org/) for versioning.

## Authors

* **Hicham NAIMI**, for any suggestion you can contact me [HERE](mailto:hicham.naimi.hn@gmail.com)

## License

This project is licensed under the MIT License.

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