cached-factory 0.0.2 โ 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -25
- package/lib/index.d.ts +8 -5
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +23 -21
- package/lib/index.js.map +1 -1
- package/package.json +40 -54
package/README.md
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
<h1 align="center">cached-factory</h1>
|
|
2
2
|
|
|
3
|
-
<p align="center">
|
|
3
|
+
<p align="center">
|
|
4
|
+
Creates and caches values under keys.
|
|
5
|
+
๐ญ
|
|
6
|
+
</p>
|
|
4
7
|
|
|
5
8
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<!--
|
|
8
|
-
|
|
9
|
-
<img alt="All Contributors: 1" src="https://img.shields.io/badge/all_contributors-1-21bb42.svg" />
|
|
9
|
+
<!-- prettier-ignore-start -->
|
|
10
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
11
|
+
<a href="#contributors" target="_blank"><img alt="๐ช All Contributors: 2" src="https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-2-21bb42.svg" /></a>
|
|
10
12
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
11
|
-
<!-- prettier-ignore-end -->
|
|
12
|
-
|
|
13
|
-
<a href="https://codecov.io/gh/JoshuaKGoldberg/cached-factory" target="_blank">
|
|
14
|
-
<img alt="
|
|
15
|
-
|
|
16
|
-
<
|
|
17
|
-
<img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" />
|
|
18
|
-
</a>
|
|
19
|
-
<a href="https://github.com/JoshuaKGoldberg/cached-factory/blob/main/LICENSE.md" target="_blank">
|
|
20
|
-
<img alt="License: MIT" src="https://img.shields.io/github/license/JoshuaKGoldberg/cached-factory?color=21bb42">
|
|
21
|
-
</a>
|
|
22
|
-
<img alt="Style: Prettier" src="https://img.shields.io/badge/style-prettier-21bb42.svg" />
|
|
23
|
-
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />
|
|
13
|
+
<!-- prettier-ignore-end -->
|
|
14
|
+
<a href="https://github.com/JoshuaKGoldberg/cached-factory/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="๐ค Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
|
|
15
|
+
<a href="https://codecov.io/gh/JoshuaKGoldberg/cached-factory" target="_blank"><img alt="๐งช Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/cached-factory?label=%F0%9F%A7%AA%20coverage" /></a>
|
|
16
|
+
<a href="https://github.com/JoshuaKGoldberg/cached-factory/blob/main/LICENSE.md" target="_blank"><img alt="๐ License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg" /></a>
|
|
17
|
+
<a href="http://npmjs.com/package/cached-factory" target="_blank"><img alt="๐ฆ npm version" src="https://img.shields.io/npm/v/cached-factory?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
|
|
18
|
+
<img alt="๐ช TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
|
|
24
19
|
</p>
|
|
25
20
|
|
|
26
21
|
## Usage
|
|
@@ -44,7 +39,7 @@ const cache = new CachedFactory((key) => ({ key }));
|
|
|
44
39
|
cache.get("banana");
|
|
45
40
|
|
|
46
41
|
// true
|
|
47
|
-
cache.get("banana") ===
|
|
42
|
+
cache.get("banana") === cache.get("banana");
|
|
48
43
|
```
|
|
49
44
|
|
|
50
45
|
### Asynchronous Factories
|
|
@@ -76,7 +71,8 @@ cache.clear();
|
|
|
76
71
|
|
|
77
72
|
### TypeScript
|
|
78
73
|
|
|
79
|
-
`CachedFactory` is written in TypeScript and ships with strong typing.
|
|
74
|
+
`CachedFactory` is written in TypeScript and ships with strong typing.
|
|
75
|
+
๐ช
|
|
80
76
|
|
|
81
77
|
> ๐ Tip: if you're working with [`noImplicitAny`](https://aka.ms/tsconfig#noImplicitAny) enabled _(which is generally a good idea)_, an inline function provided as an argument to `CachedFactory` may need an explicit type annotation for its key.
|
|
82
78
|
>
|
|
@@ -84,26 +80,28 @@ cache.clear();
|
|
|
84
80
|
> new CachedFactory((key: string) => `Cached: ${key}!`);
|
|
85
81
|
> ```
|
|
86
82
|
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).
|
|
86
|
+
Thanks! ๐ญ
|
|
87
|
+
|
|
87
88
|
## Contributors
|
|
88
89
|
|
|
89
90
|
<!-- spellchecker: disable -->
|
|
90
91
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
91
92
|
<!-- prettier-ignore-start -->
|
|
92
|
-
<!-- markdownlint-disable -->
|
|
93
93
|
<table>
|
|
94
94
|
<tbody>
|
|
95
95
|
<tr>
|
|
96
|
+
<td align="center" valign="top" width="14.28%"><a href="http://lishaduck.github.io"><img src="https://avatars.githubusercontent.com/u/88557639?v=4?s=100" width="100px;" alt="Eli"/><br /><sub><b>Eli</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/cached-factory/issues?q=author%3Alishaduck" title="Bug reports">๐</a></td>
|
|
96
97
|
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg โจ"/><br /><sub><b>Josh Goldberg โจ</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/cached-factory/commits?author=JoshuaKGoldberg" title="Code">๐ป</a> <a href="#content-JoshuaKGoldberg" title="Content">๐</a> <a href="https://github.com/JoshuaKGoldberg/cached-factory/commits?author=JoshuaKGoldberg" title="Documentation">๐</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">๐ค</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">๐</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">๐ง</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">๐</a> <a href="#tool-JoshuaKGoldberg" title="Tools">๐ง</a></td>
|
|
97
98
|
</tr>
|
|
98
99
|
</tbody>
|
|
99
100
|
</table>
|
|
100
101
|
|
|
101
|
-
<!-- markdownlint-restore -->
|
|
102
102
|
<!-- prettier-ignore-end -->
|
|
103
103
|
|
|
104
104
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
105
105
|
<!-- spellchecker: enable -->
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
> ๐ This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [template-typescript-node-package](https://github.com/JoshuaKGoldberg/template-typescript-node-package).
|
|
107
|
+
> ๐ This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app) using the [Bingo framework](https://create.bingo).
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
1
2
|
type Factory<Key, Value> = (key: Key) => Value;
|
|
2
3
|
declare class CachedFactory<Key, Value> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
#private;
|
|
5
|
+
constructor(factory: Factory<Key, Value>);
|
|
6
|
+
clear(): void;
|
|
7
|
+
entries(): MapIterator<[Key, Value]>;
|
|
8
|
+
get(key: Key): Value;
|
|
7
9
|
}
|
|
8
|
-
|
|
10
|
+
//#endregion
|
|
9
11
|
export { CachedFactory, Factory };
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY,OAAA,gBAAuB,GAAA,EAAK,GAAA,KAAQ,KAAA;AAAA,cAEnC,aAAA;EAAA;cAIA,OAAA,EAAS,OAAA,CAAQ,GAAA,EAAK,KAAA;EAIlC,KAAA,CAAA;EAIA,OAAA,CAAA,GAAO,WAAA,EAAA,GAAA,EAAA,KAAA;EAIP,GAAA,CAAI,GAAA,EAAK,GAAA,GAAG,KAAA;AAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
CachedFactory
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
var CachedFactory = class {
|
|
3
|
+
#cache = /* @__PURE__ */ new Map();
|
|
4
|
+
#getter;
|
|
5
|
+
constructor(factory) {
|
|
6
|
+
this.#getter = factory;
|
|
7
|
+
}
|
|
8
|
+
clear() {
|
|
9
|
+
this.#cache.clear();
|
|
10
|
+
}
|
|
11
|
+
entries() {
|
|
12
|
+
return this.#cache.entries();
|
|
13
|
+
}
|
|
14
|
+
get(key) {
|
|
15
|
+
const existing = this.#cache.get(key);
|
|
16
|
+
if (existing) return existing;
|
|
17
|
+
const value = this.#getter(key);
|
|
18
|
+
this.#cache.set(key, value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
22
21
|
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CachedFactory };
|
|
24
|
+
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type Factory<Key, Value> = (key: Key) => Value;\n\nexport class CachedFactory<Key, Value> {\n\t#cache = new Map<Key, Value>();\n\t#getter: Factory<Key, Value>;\n\n\tconstructor(factory: Factory<Key, Value>) {\n\t\tthis.#getter = factory;\n\t}\n\n\tclear() {\n\t\tthis.#cache.clear();\n\t}\n\n\tget(key: Key) {\n\t\tconst existing = this.#cache.get(key);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst value = this.#getter(key);\n\t\tthis.#cache.set(key, value);\n\t\treturn value;\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["#getter","#cache"],"sources":["../src/index.ts"],"sourcesContent":["export type Factory<Key, Value> = (key: Key) => Value;\n\nexport class CachedFactory<Key, Value> {\n\t#cache = new Map<Key, Value>();\n\t#getter: Factory<Key, Value>;\n\n\tconstructor(factory: Factory<Key, Value>) {\n\t\tthis.#getter = factory;\n\t}\n\n\tclear() {\n\t\tthis.#cache.clear();\n\t}\n\n\tentries() {\n\t\treturn this.#cache.entries();\n\t}\n\n\tget(key: Key) {\n\t\tconst existing = this.#cache.get(key);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst value = this.#getter(key);\n\t\tthis.#cache.set(key, value);\n\t\treturn value;\n\t}\n}\n"],"mappings":";AAEA,IAAa,gBAAb,MAAuC;CACtC,yBAAS,IAAI,KAAiB;CAC9B;CAEA,YAAY,SAA8B;AACzC,QAAA,SAAe;;CAGhB,QAAQ;AACP,QAAA,MAAY,OAAO;;CAGpB,UAAU;AACT,SAAO,MAAA,MAAY,SAAS;;CAG7B,IAAI,KAAU;EACb,MAAM,WAAW,MAAA,MAAY,IAAI,IAAI;AACrC,MAAI,SACH,QAAO;EAGR,MAAM,QAAQ,MAAA,OAAa,IAAI;AAC/B,QAAA,MAAY,IAAI,KAAK,MAAM;AAC3B,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cached-factory",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Creates and caches values under keys. ๐ญ",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/JoshuaKGoldberg/cached-factory"
|
|
7
|
+
"url": "git+https://github.com/JoshuaKGoldberg/cached-factory.git"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": {
|
|
@@ -12,25 +12,19 @@
|
|
|
12
12
|
"email": "npm@joshuakgoldberg.com"
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
|
-
"main": "
|
|
15
|
+
"main": "lib/index.js",
|
|
16
16
|
"files": [
|
|
17
|
-
"lib/"
|
|
18
|
-
"package.json",
|
|
19
|
-
"LICENSE.md",
|
|
20
|
-
"README.md"
|
|
17
|
+
"lib/"
|
|
21
18
|
],
|
|
22
19
|
"scripts": {
|
|
23
|
-
"build": "
|
|
24
|
-
"format": "prettier
|
|
20
|
+
"build": "tsdown",
|
|
21
|
+
"format": "prettier .",
|
|
25
22
|
"format:write": "pnpm format --write",
|
|
26
|
-
"lint": "eslint .
|
|
23
|
+
"lint": "eslint . --max-warnings 0",
|
|
27
24
|
"lint:knip": "knip",
|
|
28
|
-
"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
|
|
29
|
-
"lint:package-json": "npmPkgJsonLint .",
|
|
30
25
|
"lint:packages": "pnpm dedupe --check",
|
|
31
26
|
"lint:spelling": "cspell \"**\" \".github/**/*\"",
|
|
32
|
-
"prepare": "husky
|
|
33
|
-
"should-semantic-release": "should-semantic-release --verbose",
|
|
27
|
+
"prepare": "husky",
|
|
34
28
|
"test": "vitest",
|
|
35
29
|
"tsc": "tsc"
|
|
36
30
|
},
|
|
@@ -38,51 +32,43 @@
|
|
|
38
32
|
"*": "prettier --ignore-unknown --write"
|
|
39
33
|
},
|
|
40
34
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"eslint": "
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"eslint
|
|
52
|
-
"eslint-plugin-jsdoc": "
|
|
53
|
-
"eslint-plugin-jsonc": "
|
|
54
|
-
"eslint-plugin-
|
|
55
|
-
"eslint-plugin-
|
|
56
|
-
"eslint-plugin-
|
|
57
|
-
"eslint-plugin-
|
|
58
|
-
"eslint-plugin-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"release-it": "^16.1.5",
|
|
73
|
-
"sentences-per-line": "^0.2.1",
|
|
74
|
-
"should-semantic-release": "^0.1.1",
|
|
75
|
-
"tsup": "^7.2.0",
|
|
76
|
-
"typescript": "^5.1.6",
|
|
77
|
-
"vitest": "^0.34.3",
|
|
78
|
-
"yaml-eslint-parser": "^1.2.2"
|
|
35
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.7.1",
|
|
36
|
+
"@eslint/js": "10.0.1",
|
|
37
|
+
"@eslint/markdown": "8.0.1",
|
|
38
|
+
"@release-it/conventional-changelog": "11.0.0",
|
|
39
|
+
"@types/node": "25.6.0",
|
|
40
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
41
|
+
"@vitest/eslint-plugin": "1.6.16",
|
|
42
|
+
"console-fail-test": "0.6.1",
|
|
43
|
+
"create-typescript-app": "2.60.1",
|
|
44
|
+
"cspell": "10.0.0",
|
|
45
|
+
"eslint": "10.2.1",
|
|
46
|
+
"eslint-plugin-jsdoc": "62.9.0",
|
|
47
|
+
"eslint-plugin-jsonc": "3.1.2",
|
|
48
|
+
"eslint-plugin-n": "17.24.0",
|
|
49
|
+
"eslint-plugin-package-json": "0.91.1",
|
|
50
|
+
"eslint-plugin-perfectionist": "5.9.0",
|
|
51
|
+
"eslint-plugin-regexp": "3.1.0",
|
|
52
|
+
"eslint-plugin-yml": "3.3.1",
|
|
53
|
+
"husky": "9.1.7",
|
|
54
|
+
"knip": "6.7.0",
|
|
55
|
+
"lint-staged": "16.4.0",
|
|
56
|
+
"prettier": "3.8.3",
|
|
57
|
+
"prettier-plugin-curly": "0.4.1",
|
|
58
|
+
"prettier-plugin-packagejson": "3.0.2",
|
|
59
|
+
"prettier-plugin-sentences-per-line": "0.2.3",
|
|
60
|
+
"prettier-plugin-sh": "0.18.1",
|
|
61
|
+
"release-it": "20.0.1",
|
|
62
|
+
"tsdown": "0.21.10",
|
|
63
|
+
"typescript": "6.0.3",
|
|
64
|
+
"typescript-eslint": "8.59.0",
|
|
65
|
+
"vitest": "4.1.5"
|
|
79
66
|
},
|
|
80
|
-
"packageManager": "pnpm@
|
|
67
|
+
"packageManager": "pnpm@10.33.2",
|
|
81
68
|
"engines": {
|
|
82
69
|
"node": ">=18"
|
|
83
70
|
},
|
|
84
71
|
"publishConfig": {
|
|
85
|
-
"access": "public",
|
|
86
72
|
"provenance": true
|
|
87
73
|
}
|
|
88
74
|
}
|