Skip to content

Commit

Permalink
feat(esm): convert to esm, npm update, noissue (#40)
Browse files Browse the repository at this point in the history
BREAKING CHANGES

Requires ESM loader

* feat(esm): convert to esm, npm update, noissue

* chore(deps): npm audit fix

* docs(esm): convert examples to esm format
  • Loading branch information
MrSwitch authored Aug 3, 2022
1 parent e2cf1b5 commit e391722
Show file tree
Hide file tree
Showing 5 changed files with 708 additions and 402 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
!Warning contrived example ahead...

```js
const got = require('got'); // simple http requst library for the purpose of demonstration
const memoize = require('@5app/memoize');
import got from 'got'; // simple http requst library for the purpose of demonstration
import memoize from '@5app/memoize';

// Let's say we're going to decorate an add function... it's
// Let's decorate the got function
const memoGot = memoize(got);

// Simultaneously open two connections...
const link = 'https://github.com';
Promise.all([memoGot(link), memoGot(link)];

// only one request is actually made, the second will piggy back off the first.
// Will call...
// GET https://github.com
// ... but that's it, it wont call it again the second request will piggy back off the first.
```
# Options `memoize(handler, {...options})`
Expand All @@ -39,7 +41,8 @@ Whether to use cache this can be a Boolean value (useful to disable it when test
This snippet checks the cached value before deciding whether to use it...
```js
const memoize = require('@5app/memoize');
import memoize from '@5app/memoize';

const memoGot = memoize(got, {
/**
* @param {object} cached_response - Cached Object
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @param {number} [opts.cacheMaxSize=1000] - Maximum Cache Size
* @returns {Function} The decorated callback function
*/
function Memoize(callback, opts = {}) {
export default function Memoize(callback, opts = {}) {
// Disable all memoize
const {MEMOIZE_DISABLE = false} = process.env;

Expand Down Expand Up @@ -135,5 +135,3 @@ function Memoize(callback, opts = {}) {
return item.value;
};
}

module.exports = Memoize;
Loading

0 comments on commit e391722

Please sign in to comment.