# ts-memoize

> Use memoize pattern in your TypeScript code with only one API.

Latest version **0.2.0** (published 2020-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-memoize
pnpm add ts-memoize
yarn add ts-memoize
bun add ts-memoize
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-03-28 |
| First published | 2020-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wendzhue |

## Links

- npm: https://www.npmjs.com/package/ts-memoize
- npm.io page: https://npm.io/package/ts-memoize

## Recent versions

- 0.2.0 (latest) — 2020-03-28

## README

# ts-memoize

Use memoize pattern in your TypeScript code with only one API.

## Installation

```bash
npm install ts-memoize

# or yarn
yarn add ts-memoize
```

## Usage

```ts
import memoize from 'ts-memoize';
```

For function:

```ts
const memoizedGetter = memoize((a, b) => {
  // the function should not depend on values outside of its scope
  return someHeavyRevaluation(a, b);
});
```

For class:

```ts
// on getter (& setter)
class A {
  @memoize
  public get a() {
    return someHeavyRevaluation();
  }

  public set value(val) {
    // re-evaluate when the setter is invoked
  }
}

// on method
class B {
  @memoize
  public getFunction(param) {
    // re-evaluate when arguments change
    return someHeavyRevaluation(param);
  }
}
```

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