cached-factory 0.1.0 โ†’ 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 CHANGED
@@ -1,26 +1,21 @@
1
1
  <h1 align="center">cached-factory</h1>
2
2
 
3
- <p align="center">Creates and caches values under keys. ๐Ÿญ</p>
3
+ <p align="center">
4
+ Creates and caches values under keys.
5
+ ๐Ÿญ
6
+ </p>
4
7
 
5
8
  <p align="center">
6
- <a href="#contributors" target="_blank">
7
- <!-- prettier-ignore-start -->
8
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
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
- </a>
13
- <a href="https://codecov.io/gh/JoshuaKGoldberg/cached-factory" target="_blank">
14
- <img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/cached-factory/branch/main/graph/badge.svg"/>
15
- </a>
16
- <a href="https://github.com/JoshuaKGoldberg/cached-factory/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank">
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") === cached.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
- <!-- You can remove this notice if you don't want it ๐Ÿ™‚ no worries! -->
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,10 +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
- #private;
4
- constructor(factory: Factory<Key, Value>);
5
- clear(): void;
6
- entries(): IterableIterator<[Key, Value]>;
7
- get(key: Key): Value;
4
+ #private;
5
+ constructor(factory: Factory<Key, Value>);
6
+ clear(): void;
7
+ entries(): MapIterator<[Key, Value]>;
8
+ get(key: Key): Value;
8
9
  }
9
-
10
+ //#endregion
10
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,26 +1,25 @@
1
- class CachedFactory {
2
- #cache = /* @__PURE__ */ new Map();
3
- #getter;
4
- constructor(factory) {
5
- this.#getter = factory;
6
- }
7
- clear() {
8
- this.#cache.clear();
9
- }
10
- entries() {
11
- return this.#cache.entries();
12
- }
13
- get(key) {
14
- const existing = this.#cache.get(key);
15
- if (existing) {
16
- return existing;
17
- }
18
- const value = this.#getter(key);
19
- this.#cache.set(key, value);
20
- return value;
21
- }
22
- }
23
- export {
24
- 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
+ }
25
21
  };
22
+ //#endregion
23
+ export { CachedFactory };
24
+
26
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\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":"AAEO,MAAM,cAA0B;AAAA,EACtC,SAAS,oBAAI,IAAgB;AAAA,EAC7B;AAAA,EAEA,YAAY,SAA8B;AACzC,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,QAAQ;AACP,SAAK,OAAO,MAAM;AAAA,EACnB;AAAA,EAEA,UAAU;AACT,WAAO,KAAK,OAAO,QAAQ;AAAA,EAC5B;AAAA,EAEA,IAAI,KAAU;AACb,UAAM,WAAW,KAAK,OAAO,IAAI,GAAG;AACpC,QAAI,UAAU;AACb,aAAO;AAAA,IACR;AAEA,UAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,SAAK,OAAO,IAAI,KAAK,KAAK;AAC1B,WAAO;AAAA,EACR;AACD;","names":[]}
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.1.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": "./lib/index.js",
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": "tsup",
24
- "format": "prettier \"**/*\" --ignore-unknown",
20
+ "build": "tsdown",
21
+ "format": "prettier .",
25
22
  "format:write": "pnpm format --write",
26
- "lint": "eslint . .*js --max-warnings 0 --report-unused-disable-directives",
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 install",
33
- "should-semantic-release": "should-semantic-release --verbose",
27
+ "prepare": "husky",
34
28
  "test": "vitest",
35
29
  "tsc": "tsc"
36
30
  },
@@ -38,47 +32,43 @@
38
32
  "*": "prettier --ignore-unknown --write"
39
33
  },
40
34
  "devDependencies": {
41
- "@types/eslint": "^8.44.2",
42
- "@typescript-eslint/eslint-plugin": "^6.4.1",
43
- "@typescript-eslint/parser": "^6.4.1",
44
- "@vitest/coverage-istanbul": "^0.34.3",
45
- "console-fail-test": "^0.2.3",
46
- "cspell": "^7.0.1",
47
- "eslint": "^8.48.0",
48
- "eslint-config-prettier": "^9.0.0",
49
- "eslint-plugin-deprecation": "^1.5.0",
50
- "eslint-plugin-eslint-comments": "^3.2.0",
51
- "eslint-plugin-import": "^2.28.1",
52
- "eslint-plugin-jsdoc": "^46.5.0",
53
- "eslint-plugin-jsonc": "^2.9.0",
54
- "eslint-plugin-markdown": "^3.0.1",
55
- "eslint-plugin-n": "^16.0.2",
56
- "eslint-plugin-no-only-tests": "^3.1.0",
57
- "eslint-plugin-perfectionist": "^1.5.1",
58
- "eslint-plugin-regexp": "^1.15.0",
59
- "eslint-plugin-vitest": "^0.2.8",
60
- "eslint-plugin-yml": "^1.8.0",
61
- "husky": "^8.0.3",
62
- "jsonc-eslint-parser": "^2.3.0",
63
- "knip": "^2.20.1",
64
- "lint-staged": "^14.0.1",
65
- "markdownlint": "^0.30.0",
66
- "markdownlint-cli": "^0.35.0",
67
- "npm-package-json-lint": "^7.0.0",
68
- "npm-package-json-lint-config-default": "^6.0.0",
69
- "prettier": "^3.0.2",
70
- "prettier-plugin-curly": "^0.1.2",
71
- "prettier-plugin-packagejson": "^2.4.5",
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@9.15.0",
67
+ "packageManager": "pnpm@10.33.2",
81
68
  "engines": {
82
69
  "node": ">=18"
70
+ },
71
+ "publishConfig": {
72
+ "provenance": true
83
73
  }
84
74
  }