{"id":19926616,"url":"https://github.com/microlinkhq/memoize-token","last_synced_at":"2025-05-03T08:32:29.324Z","repository":{"id":41571019,"uuid":"149482355","full_name":"microlinkhq/memoize-token","owner":"microlinkhq","description":"A memoize library for refreshing and cache token values.","archived":false,"fork":false,"pushed_at":"2024-12-07T15:38:45.000Z","size":70,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T08:17:32.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microlinkhq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-19T16:45:00.000Z","updated_at":"2024-12-07T15:38:49.000Z","dependencies_parsed_at":"2022-08-20T08:50:23.130Z","dependency_job_id":"1457c08c-430c-4805-b091-5ed885801e96","html_url":"https://github.com/microlinkhq/memoize-token","commit_stats":{"total_commits":35,"total_committers":3,"mean_commits":"11.666666666666666","dds":"0.11428571428571432","last_synced_commit":"e1a2229d79f60ae243f1f4cfd5a3ed8f59026417"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fmemoize-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fmemoize-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fmemoize-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microlinkhq%2Fmemoize-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microlinkhq","download_url":"https://codeload.github.com/microlinkhq/memoize-token/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252162538,"owners_count":21704270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T22:29:57.538Z","updated_at":"2025-05-03T08:32:28.986Z","avatar_url":"https://github.com/microlinkhq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner.png#gh-light-mode-only\" alt=\"microlink logo\"\u003e\n  \u003cimg src=\"https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner-dark.png#gh-dark-mode-only\" alt=\"microlink logo\"\u003e\n\u003c/div\u003e\n\n![Last version](https://img.shields.io/github/tag/microlinkhq/memoize-token.svg?style=flat-square)\n[![NPM Status](https://img.shields.io/npm/dm/memoize-token.svg?style=flat-square)](https://www.npmjs.org/package/memoize-token)\n\n\u003e A memoize library for refreshing and cache token values.\n\n## Install\n\n```bash\n$ npm install memoize-token --save\n```\n\n## Usage\n\n```js\nconst memoizeToken = require('memoize-token')\nlet value = -1\nconst values = ['foo', 'bar']\n\nconst fn = memoizeToken(\n  () =\u003e values[++value],\n  { max: 2, key: 'test', cache }\n)\n\n;(async () =\u003e {\n  await fn() // =\u003e 'foo'\n  await fn() // =\u003e 'foo'\n  await fn() // max excedeed, refresh the token =\u003e 'bar'\n  await fn() // =\u003e 'bar'\n})()\n```\n\n## API\n\n### memoizeToken(fn, [options])\n\n#### fn\n\n*Required*\u003cbr\u003e\nType: `Function`\n\nFunction to be memoized and used for refreshing the token.\n\n#### options\n\n##### max\n\n*Required*\u003cbr\u003e\nType: `Number`\u003cbr\u003e\n\nMaximum numbers of calls after refresh the token.\n\n##### key\n\n*Required*\u003cbr\u003e\nType: `String`\u003cbr\u003e\n\nThe base key to use into the cache.\n\n##### expire\n\nType: `Number`\u003cbr\u003e\n\nTime in milliseconds to consider a token as expired.\n\n##### cache\n\nType: `Object`\u003cbr\u003e\nDefault: `new Map()`\n\nUse a different cache storage.\n\nMust implement the following methods: `.get(key)` and `.set(key, value)`, Check [`keyv`](https://github.com/lukechilds/keyv) to see database connectors.\n\n## Related\n\n- [bottleneck](https://github.com/SGrondin/bottleneck) – Job scheduler and rate limiter.\n- [limiter](https://github.com/jhurliman/node-rate-limiter) – Provides a generic rate limiter and token bucket for Node.js.\n\n## License\n\n**memoize-token** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/memoize-token/blob/master/LICENSE.md) License.\u003cbr\u003e\nAuthored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/memoize-token/contributors).\n\n\u003e [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrolinkhq%2Fmemoize-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrolinkhq%2Fmemoize-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrolinkhq%2Fmemoize-token/lists"}