Skip to main content

Built and signed on GitHub Actions

Memoize any function

This package works with Bun, Cloudflare Workers, Node.js, Deno, Browsers
JSR Score
100%
Published
3 days ago (0.1.3)

memz JSR

Memoize any function.

import memoize from "jsr:@korkje/memz";

const add = memoize((a: number, b: number) => a + b);

Recursion:

const fib = memoize((n: number): number => {
    if (n < 2) {
        return n;
    }

    return fib(n - 2) + fib(n - 1);
});

Initial cache:

const cache = { "0": 0, "1": 1 };
const fib = memoize((n: number): number => fib(n - 2) + fib(n - 1), cache);
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @korkje/memz

Import symbol

import * as mod from "@korkje/memz";

Add Package

npx jsr add @korkje/memz

Import symbol

import * as mod from "@korkje/memz";

Add Package

yarn dlx jsr add @korkje/memz

Import symbol

import * as mod from "@korkje/memz";

Add Package

pnpm dlx jsr add @korkje/memz

Import symbol

import * as mod from "@korkje/memz";

Add Package

bunx jsr add @korkje/memz

Import symbol

import * as mod from "@korkje/memz";