@zthun/helpful-reflection 9.0.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ # MIT License
2
+
3
+ Copyright © 2025 Anthony Bonta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Helpful Functions
2
+
3
+ Provides reflection decorators that halp describe metadata about a class,
4
+ function, or field.
5
+
6
+ ## Installation
7
+
8
+ ```sh
9
+ # NPM
10
+ npm install @zthun/helpful-reflection
11
+ # Yarn
12
+ yarn add @zthun/helpful-reflection
13
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const helpfulFn = require("@zthun/helpful-fn");
4
+ const noConflict = require("reflect-metadata/no-conflict");
5
+ const Key = "zthunworks:tags";
6
+ function ZTag(by) {
7
+ return (target, property) => {
8
+ if (property == null) {
9
+ const current = helpfulFn.firstDefined({}, noConflict.getMetadata(Key, target));
10
+ noConflict.defineMetadata(Key, { ...current, [by]: true }, target);
11
+ } else {
12
+ const current = helpfulFn.firstDefined({}, noConflict.getMetadata(Key, target, property));
13
+ noConflict.defineMetadata(Key, { ...current, [by]: true }, target, property);
14
+ }
15
+ };
16
+ }
17
+ function isTagged(by, target, property) {
18
+ if (target == null || typeof target !== "function" && typeof target !== "object") {
19
+ return false;
20
+ }
21
+ const tags = property ? noConflict.getMetadata(Key, target, property) : noConflict.getMetadata(Key, target);
22
+ return Object.prototype.hasOwnProperty.call(helpfulFn.firstDefined({}, tags), by);
23
+ }
24
+ exports.ZTag = ZTag;
25
+ exports.isTagged = isTagged;
26
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/tag/tag.ts"],"sourcesContent":["import { firstDefined } from \"@zthun/helpful-fn\";\nimport { defineMetadata, getMetadata } from \"reflect-metadata/no-conflict\";\n\nconst Key = \"zthunworks:tags\";\n\nexport function ZTag(\n by: string,\n): MethodDecorator & ClassDecorator & PropertyDecorator {\n return (target: any, property?: string | symbol) => {\n if (property == null) {\n // Class.\n const current = firstDefined({}, getMetadata(Key, target));\n defineMetadata(Key, { ...current, [by]: true }, target);\n } else {\n // Member.\n const current = firstDefined({}, getMetadata(Key, target, property));\n defineMetadata(Key, { ...current, [by]: true }, target, property);\n }\n };\n}\n\nexport function isTagged(\n by: string,\n target: any,\n property?: string | symbol,\n): boolean {\n if (\n target == null ||\n (typeof target !== \"function\" && typeof target !== \"object\")\n ) {\n return false;\n }\n\n const tags = property\n ? getMetadata(Key, target, property)\n : getMetadata(Key, target);\n\n return Object.prototype.hasOwnProperty.call(firstDefined({}, tags), by);\n}\n"],"names":["firstDefined","getMetadata","defineMetadata"],"mappings":";;;;AAGA,MAAM,MAAM;AAEL,SAAS,KACd,IACsD;AAC/C,SAAA,CAAC,QAAa,aAA+B;AAClD,QAAI,YAAY,MAAM;AAEpB,YAAM,UAAUA,UAAAA,aAAa,CAAA,GAAIC,WAAAA,YAAY,KAAK,MAAM,CAAC;AAC1CC,iBAAA,eAAA,KAAK,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,KAAK,GAAG,MAAM;AAAA,IAAA,OACjD;AAEC,YAAA,UAAUF,UAAAA,aAAa,CAAC,GAAGC,uBAAY,KAAK,QAAQ,QAAQ,CAAC;AACpDC,gCAAA,KAAK,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,KAAA,GAAQ,QAAQ,QAAQ;AAAA,IAAA;AAAA,EAEpE;AACF;AAEgB,SAAA,SACd,IACA,QACA,UACS;AACT,MACE,UAAU,QACT,OAAO,WAAW,cAAc,OAAO,WAAW,UACnD;AACO,WAAA;AAAA,EAAA;AAGH,QAAA,OAAO,WACTD,WAAAA,YAAY,KAAK,QAAQ,QAAQ,IACjCA,WAAAA,YAAY,KAAK,MAAM;AAEpB,SAAA,OAAO,UAAU,eAAe,KAAKD,UAAAA,aAAa,CAAC,GAAG,IAAI,GAAG,EAAE;AACxE;;;"}
@@ -0,0 +1 @@
1
+ export * from './tag/tag.js';
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ import { firstDefined } from "@zthun/helpful-fn";
2
+ import { getMetadata, defineMetadata } from "reflect-metadata/no-conflict";
3
+ const Key = "zthunworks:tags";
4
+ function ZTag(by) {
5
+ return (target, property) => {
6
+ if (property == null) {
7
+ const current = firstDefined({}, getMetadata(Key, target));
8
+ defineMetadata(Key, { ...current, [by]: true }, target);
9
+ } else {
10
+ const current = firstDefined({}, getMetadata(Key, target, property));
11
+ defineMetadata(Key, { ...current, [by]: true }, target, property);
12
+ }
13
+ };
14
+ }
15
+ function isTagged(by, target, property) {
16
+ if (target == null || typeof target !== "function" && typeof target !== "object") {
17
+ return false;
18
+ }
19
+ const tags = property ? getMetadata(Key, target, property) : getMetadata(Key, target);
20
+ return Object.prototype.hasOwnProperty.call(firstDefined({}, tags), by);
21
+ }
22
+ export {
23
+ ZTag,
24
+ isTagged
25
+ };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/tag/tag.ts"],"sourcesContent":["import { firstDefined } from \"@zthun/helpful-fn\";\nimport { defineMetadata, getMetadata } from \"reflect-metadata/no-conflict\";\n\nconst Key = \"zthunworks:tags\";\n\nexport function ZTag(\n by: string,\n): MethodDecorator & ClassDecorator & PropertyDecorator {\n return (target: any, property?: string | symbol) => {\n if (property == null) {\n // Class.\n const current = firstDefined({}, getMetadata(Key, target));\n defineMetadata(Key, { ...current, [by]: true }, target);\n } else {\n // Member.\n const current = firstDefined({}, getMetadata(Key, target, property));\n defineMetadata(Key, { ...current, [by]: true }, target, property);\n }\n };\n}\n\nexport function isTagged(\n by: string,\n target: any,\n property?: string | symbol,\n): boolean {\n if (\n target == null ||\n (typeof target !== \"function\" && typeof target !== \"object\")\n ) {\n return false;\n }\n\n const tags = property\n ? getMetadata(Key, target, property)\n : getMetadata(Key, target);\n\n return Object.prototype.hasOwnProperty.call(firstDefined({}, tags), by);\n}\n"],"names":[],"mappings":";;AAGA,MAAM,MAAM;AAEL,SAAS,KACd,IACsD;AAC/C,SAAA,CAAC,QAAa,aAA+B;AAClD,QAAI,YAAY,MAAM;AAEpB,YAAM,UAAU,aAAa,CAAA,GAAI,YAAY,KAAK,MAAM,CAAC;AAC1C,qBAAA,KAAK,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,KAAK,GAAG,MAAM;AAAA,IAAA,OACjD;AAEC,YAAA,UAAU,aAAa,CAAC,GAAG,YAAY,KAAK,QAAQ,QAAQ,CAAC;AACpD,qBAAA,KAAK,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,KAAA,GAAQ,QAAQ,QAAQ;AAAA,IAAA;AAAA,EAEpE;AACF;AAEgB,SAAA,SACd,IACA,QACA,UACS;AACT,MACE,UAAU,QACT,OAAO,WAAW,cAAc,OAAO,WAAW,UACnD;AACO,WAAA;AAAA,EAAA;AAGH,QAAA,OAAO,WACT,YAAY,KAAK,QAAQ,QAAQ,IACjC,YAAY,KAAK,MAAM;AAEpB,SAAA,OAAO,UAAU,eAAe,KAAK,aAAa,CAAC,GAAG,IAAI,GAAG,EAAE;AACxE;"}
@@ -0,0 +1,2 @@
1
+ export declare function ZTag(by: string): MethodDecorator & ClassDecorator & PropertyDecorator;
2
+ export declare function isTagged(by: string, target: any, property?: string | symbol): boolean;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@zthun/helpful-reflection",
3
+ "version": "9.0.0",
4
+ "description": "Helpful decorators built around reflect-metadata.",
5
+ "author": "Anthony Bonta",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zthun/helpful",
10
+ "directory": "packages/helpful-reflection"
11
+ },
12
+ "type": "module",
13
+ "types": "./dist/index.d.mts",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "exports": {
17
+ "types": "./dist/index.d.mts",
18
+ "require": "./dist/index.cjs",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "scripts": {
22
+ "build": "vite build"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "@zthun/helpful-fn": "^9.0.0",
29
+ "reflect-metadata": "^0.2.2"
30
+ },
31
+ "devDependencies": {
32
+ "@zthun/janitor-build-config": "^19.2.0",
33
+ "typescript": "~5.8.3",
34
+ "vite": "^6.3.5",
35
+ "vitest": "^3.2.4"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "sideEffects": false,
41
+ "gitHead": "0ea541ec8e23c662fbd9e56582b259926201a128"
42
+ }