More memoization. https://conduitry.dev/memor
Go to file
Conduitry 51fc73c0ed update docs 2018-03-18 03:23:25 -04:00
src POJOs: use symbol properties as well, just not in a normalized order 2018-03-18 03:20:11 -04:00
.eslintrc.yaml first version 2018-03-17 16:23:31 -04:00
.gitignore first version 2018-03-17 16:23:31 -04:00
.prettierrc first version 2018-03-17 16:23:31 -04:00
CHANGELOG.md v0.1.1 2018-03-18 02:50:42 -04:00
LICENSE add docs 2018-03-18 02:50:08 -04:00
README.md update docs 2018-03-18 03:23:25 -04:00
package.json fix Node version requirement 2018-03-18 02:56:32 -04:00
rollup.config.js first version 2018-03-17 16:23:31 -04:00
test.js POJOs: use symbol properties as well, just not in a normalized order 2018-03-18 03:20:11 -04:00

README.md

Memor: More memoization.

npm version

Memoization, but good. Works with functions of an arbitrary and/or variable number of arguments. For arrays, regexes, dates, buffers, and POJOs, caching is done according to the value (and not the identity) of the objects. Order of keys in POJOs does not matter. For other non-primitive values, memoization still works, but the caching is done by object identity.

Requirements

Usage

import { memoize } from 'memor'

const memoizedFunction = memoize(originalFunction)

memoizedFunction(/* ... */)

originalFunction can accept any number or a variable number of arguments. Re-memoizing the same function (i.e., calling memoize(originalFunction) elsewhere later) will share the cached values.

Keying of primitives, arrays, regexes, dates, and buffers works according to their values. Any additional custom properties added to the objects will not be considered as part of the key. (More specifically, arrays are keyed according to their length and their elements, regexes and buffers are keyed according to their .toString()s, and dates are keyed according to their .getTime()s.)

Keying of POJOs works according to their (own) enumerable and non-enumerable property names and values, without regard to order. Symbolic keys and their values are also part of the keying, but these are sensitive to order, due to the lack of a canonical ordering on symbols.

Other objects (those without a prototype of Object.prototype) are simply keyed according to their identity (i.e., ===).

Misc

License

Copyright (c) 2018 Conduitry