@farbenmeer/lacy 0.1.0 → 1.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/README.md +30 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/package.json +13 -8
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @farbenmeer/lacy
|
|
2
|
+
|
|
3
|
+
Lightweight utility for lazy evaluation of JavaScript promises. Chain property access and method calls without awaiting intermediate values.
|
|
4
|
+
|
|
5
|
+
**[Documentation](https://oss-docs.apps.farbenmeer.de/lacy/)** | **[GitHub](https://github.com/farbenmeer/tapi/tree/main/packages/1-lacy)** | **[npm](https://www.npmjs.com/package/@farbenmeer/lacy)**
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { lacy } from "@farbenmeer/lacy";
|
|
9
|
+
|
|
10
|
+
// Instead of this:
|
|
11
|
+
const response = await fetch("/api/users");
|
|
12
|
+
const data = await response.json();
|
|
13
|
+
const name = data[0].name;
|
|
14
|
+
|
|
15
|
+
// Write this:
|
|
16
|
+
const name = await lacy(fetch("/api/users")).json()[0].name;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @farbenmeer/lacy
|
|
23
|
+
yarn add @farbenmeer/lacy
|
|
24
|
+
pnpm add @farbenmeer/lacy
|
|
25
|
+
bun add @farbenmeer/lacy
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type Thenable<T> = {
|
|
2
|
+
then<R = T>(onfulfilled?: (value: T) => R | PromiseLike<R>, onrejected?: (reason: any) => void): Promise<R>;
|
|
3
|
+
catch(onrejected: (reason: any) => void): Promise<T>;
|
|
4
|
+
finally(onfinally: () => void): Promise<T>;
|
|
5
|
+
$: Promise<T>;
|
|
6
|
+
};
|
|
7
|
+
export type LacyPromise<T, P = never> = T extends (...args: infer A) => infer R ? (...args: A) => LacyPromise<R> : {
|
|
8
|
+
[key in Exclude<keyof T, "then" | "catch" | "finally" | "$">]: LacyPromise<T[key]>;
|
|
9
|
+
} & Thenable<T | P>;
|
|
4
10
|
export declare function lacy<T>(data: Promise<T>): LacyPromise<T>;
|
|
5
11
|
export {};
|
|
6
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,CAAC,IAAI;IACjB,IAAI,CAAC,CAAC,GAAG,CAAC,EACR,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAC9C,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GACjC,OAAO,CAAC,CAAC,CAAC,CAAC;IACd,KAAK,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAC3E,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,GAC9B;KACG,GAAG,IAAI,OAAO,CACb,MAAM,CAAC,EACP,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,GAAG,CACnC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CACxB,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAExB,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAwBxD"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,9 @@ export function lacy(data) {
|
|
|
4
4
|
if (prop === "then" || prop === "catch" || prop === "finally") {
|
|
5
5
|
return (...args) => target()[prop](...args);
|
|
6
6
|
}
|
|
7
|
+
if (prop === "$") {
|
|
8
|
+
return target();
|
|
9
|
+
}
|
|
7
10
|
return lacy(target().then((data) => {
|
|
8
11
|
if (typeof data[prop] === "function") {
|
|
9
12
|
return (...args) => data[prop](...args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farbenmeer/lacy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Michel Smola",
|
|
6
6
|
"email": "michel.smola@farbenmeer.de"
|
|
@@ -10,18 +10,23 @@
|
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"private": false,
|
|
12
12
|
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/farbenmeer/tapi.git"
|
|
16
|
+
},
|
|
13
17
|
"files": [
|
|
14
18
|
"dist"
|
|
15
19
|
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsc --noEmit false",
|
|
18
|
-
"release": "bun run build && bun publish"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@types/
|
|
21
|
+
"@types/node": "^25.0.3",
|
|
22
|
+
"vitest": "^4.0.16"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"typescript": "^5"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc --noEmit false",
|
|
29
|
+
"release": "pnpm run build && pnpm publish",
|
|
30
|
+
"test": "vitest"
|
|
26
31
|
}
|
|
27
|
-
}
|
|
32
|
+
}
|