@farbenmeer/lacy 0.1.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.
@@ -0,0 +1,6 @@
1
+ type LacyPromise<T, P = never> = T extends (...args: infer A) => infer R ? (...args: A) => LacyPromise<R> : {
2
+ [key in Exclude<keyof T, "then" | "catch" | "finally">]: LacyPromise<T[key]>;
3
+ } & Promise<T | P>;
4
+ export declare function lacy<T>(data: Promise<T>): LacyPromise<T>;
5
+ export {};
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GACpE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,GAC9B;KACG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAAG,WAAW,CAClE,CAAC,CAAC,GAAG,CAAC,CACP;CACF,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAEvB,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAqBxD"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ export function lacy(data) {
2
+ return new Proxy(() => data, {
3
+ get(target, prop) {
4
+ if (prop === "then" || prop === "catch" || prop === "finally") {
5
+ return (...args) => target()[prop](...args);
6
+ }
7
+ return lacy(target().then((data) => {
8
+ if (typeof data[prop] === "function") {
9
+ return (...args) => data[prop](...args);
10
+ }
11
+ return data[prop];
12
+ }));
13
+ },
14
+ apply(target, _thisArg, argArray) {
15
+ return lacy(target().then((method) => method(...argArray)));
16
+ },
17
+ });
18
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@farbenmeer/lacy",
3
+ "version": "0.1.0",
4
+ "author": {
5
+ "name": "Michel Smola",
6
+ "email": "michel.smola@farbenmeer.de"
7
+ },
8
+ "type": "module",
9
+ "module": "dist/index.js",
10
+ "main": "dist/index.js",
11
+ "private": false,
12
+ "license": "MIT",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc --noEmit false",
18
+ "release": "bun run build && bun publish"
19
+ },
20
+ "dependencies": {},
21
+ "devDependencies": {
22
+ "@types/bun": "latest"
23
+ },
24
+ "peerDependencies": {
25
+ "typescript": "^5"
26
+ }
27
+ }