Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

github/memoize

This is a package which provides amemoize function, as well as a TypeScriptdecorator which willmemoize a class method.

Usage

importmemoizefrom'@github/memoize'constfn=memoize(functiondoExpensiveStuff(){// Here's where you do expensive stuff!})constother=memoize(functiondoExpensiveStuff(){},{cache:newMap(),// pass your own cache implementationhash:JSON.stringify// pass your own hashing implementation})

Options:

  • hash?: (...args: A) => unknownProvides a single value to use as the Key for the memoization.Defaults toJSON.stringify (ish).
  • cache?: Map<unknown, R>The Cache implementation to provide. Must be a Map or Map-alike. Defaults to a Map.Useful for replacing the cache with an LRU cache or similar.

TypeScript Decorators Support!

This package also includes a decorator module which can be used to provideTypeScript Decorator annotations to functions.

Here's an example, showing what you need to do:

importmemoizefrom'@github/memoize/decorator'//                                  ^ note: add `/decorator` to the import to get decoratorsclassMyClass{  @memoize()// Memoize the method belowdoThings(){}}constcache=newMap()classMyClass{  @memoize({ cache})// Pass options just like the memoize functiondoThings(){}}

Why not just use package X?

Many memoize implementations exist. This one provides all of the utility we need atGitHub and nothing more. We've used a few various implementations in the past, here are some good ones:

Development

npm installnpm test

License

Distributed under the MIT license. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp