Registry / devops / memd
library0.3.16jsnpmunverified

A memoization and method control library for JavaScript/TypeScript, providing decorators for memoize, debounce, throttle, and queue. Version 0.3.16 is the latest stable release. It supports both Node.js and browser environments, includes built-in transport persistence (file, localStorage), and ships TypeScript type definitions. Differentiators include decorator-based API, per-instance caching, promise rejection clearing, and custom cache stores.

npm install memd
INSTALL
IMPORT
SIG · MEMD
M
memd
devopsjavascriptv0.3.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deco
import { deco } from 'memd'
import memd from 'memd'
The primary export is an object `deco` containing decorators. Default import gives the whole module, not the decorators directly.
Cache
import { Cache } from 'memd'
const Cache = require('memd').Cache
ESM import is recommended; CommonJS require works but may cause issues with some bundlers.
memd
import * as memd from 'memd'
import memd from 'memd'
Default import gives the namespace object, not a single function. Use namespace import for accessing FsTransport, LocalStorageTransport, etc.

Shows usage of memoize, debounce, throttle, and queue decorators, plus Cache class.

import { deco, Cache } from 'memd'; class Example { @deco.memoize({ maxAge: 5000 }) expensiveMethod(n: number): number { console.log('Computing...'); return n * 2; } @deco.debounce(200) onResize(): void { console.log('Resized'); } @deco.throttle(1000) onScroll(): void { console.log('Scrolled'); } @deco.queued({ trimQueue: true }) async fetchData(id: string): Promise<string> { const response = await fetch(`/api/data/${id}`); return response.text(); } } const example = new Example(); console.log(example.expensiveMethod(5)); // Computing... 10 console.log(example.expensiveMethod(5)); // 10 (cached) const cache = new Cache<string>({ maxAge: 10000 }); cache.set('key1', 'value1'); console.log(cache.get('key1')); // 'value1'
Debug
Known issues
gotchaDecorators are experimental in TypeScript and require `experimentalDecorators: true` in tsconfig.json.
fix
Add `"experimentalDecorators": true` to your tsconfig.json compilerOptions.
affects: all
gotchaThe `deco.memoize` decorator by default caches across all class instances. Use `perInstance: true` to cache per instance.
fix
Add `perInstance: true` to the options object: `@deco.memoize({ perInstance: true })`.
affects: >=0.1.0
gotchaWhen using `deco.debounce` with 0 or undefined ms, it uses requestAnimationFrame (browser) or setImmediate (Node). This may cause unexpected microtask timing.
fix
Specify an explicit millisecond value to avoid reliance on environment-specific behavior.
affects: >=0.1.0
deprecatedThe `deco.queue` decorator is renamed to `deco.queued` in recent versions. The old name may still work but is deprecated.
fix
Use `@deco.queued(...)` instead of `@deco.queue(...)`.
affects: >=0.2.0
Errors
Common errors & fixes
Cannot find module 'memd' or its corresponding type declarations.
TypeScript cannot resolve module types because `types` field in package.json is missing or types are not installed.
fix
Ensure you have `memd` installed and tsconfig.json includes `"moduleResolution": "node"`. If using bundler, check import path.
This expression is not callable. Type 'typeof import("memd")' has no call signatures.
Using `import memd from 'memd'` and trying to call `memd(...)` as a function, but the default export is an object with methods.
fix
Use named imports like `import { deco } from 'memd'` or use `import * as memd from 'memd'` then access `memd.deco`.
Experimental support for decorators is a feature that is subject to change in a future release.
TypeScript compiler requires `experimentalDecorators` flag to be enabled.
fix
Add `"experimentalDecorators": true` to your tsconfig.json.
Upgrade
Version history
0.3.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
packagememd
memd — npm install memd · libregistry