@reykjavik/webtools 0.3.1 → 0.3.3
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/CHANGELOG.md +13 -5
- package/README.md +29 -1
- package/errorhandling.d.ts +10 -1
- package/errorhandling.js +2 -2
- package/esm/errorhandling.d.ts +10 -1
- package/esm/errorhandling.js +2 -2
- package/esm/vanillaExtract.d.ts +1 -1
- package/esm/vanillaExtract.js +1 -1
- package/package.json +1 -1
- package/vanillaExtract.d.ts +1 -1
- package/vanillaExtract.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,13 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.3.
|
|
7
|
+
## 0.3.3
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
_2026-02-13_
|
|
10
|
+
|
|
11
|
+
- feat: Make `ResultFail` better infer its error type from the argument
|
|
12
|
+
|
|
13
|
+
## 0.3.2
|
|
10
14
|
|
|
11
|
-
-
|
|
15
|
+
_2025-12-01_
|
|
16
|
+
|
|
17
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
18
|
+
- feat: Add type `Result.PayloadOf<T>` to extract the successful payload
|
|
19
|
+
type from a `ResultTuple<T>` or a `ResultTuple`-returning function
|
|
12
20
|
|
|
13
|
-
## 0.3.0
|
|
21
|
+
## 0.3.0 – 0.3.1
|
|
14
22
|
|
|
15
23
|
_2025-11-10_
|
|
16
24
|
|
|
@@ -26,7 +34,7 @@ _2025-09-30_
|
|
|
26
34
|
|
|
27
35
|
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
28
36
|
- feat: Make `vanillaVars` return a type-safe `setVars()` helper to avoid
|
|
29
|
-
offending VSCode's CSS syntax parser too much
|
|
37
|
+
offending VSCode's CSS syntax parser too much
|
|
30
38
|
|
|
31
39
|
## 0.2.8
|
|
32
40
|
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ bun add @reykjavik/webtools
|
|
|
46
46
|
- [`Result.Success`](#resultsuccess)
|
|
47
47
|
- [`Result.Fail`](#resultfail)
|
|
48
48
|
- [`Result.throw`](#resultthrow)
|
|
49
|
+
- [Type `Result.PayloadOf`](#type-resultpayloadof)
|
|
49
50
|
- [`@reykjavik/webtools/SiteImprove`](#reykjavikwebtoolssiteimprove)
|
|
50
51
|
- [`SiteImprove` component](#siteimprove-component)
|
|
51
52
|
- [`pingSiteImprove` helper](#pingsiteimprove-helper)
|
|
@@ -838,6 +839,29 @@ try {
|
|
|
838
839
|
|
|
839
840
|
This function acts as the inverse of [`Result.catch()`](#resultcatch).
|
|
840
841
|
|
|
842
|
+
### Type `Result.PayloadOf`
|
|
843
|
+
|
|
844
|
+
**Syntax:**
|
|
845
|
+
`Result.PayloadOf<T extends | ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)>`
|
|
846
|
+
|
|
847
|
+
This utility type extracts the successful payload type `T` from a
|
|
848
|
+
`Result.Tuple<T>`-like type, a `Promise` of such type, or a function returning
|
|
849
|
+
either of those.
|
|
850
|
+
|
|
851
|
+
```ts
|
|
852
|
+
import { Result } from '@reykjavik/webtools/errorhandling';
|
|
853
|
+
|
|
854
|
+
type ResTpl = Result.Tuple<string, Error>;
|
|
855
|
+
type ResTplPromise = Promise<Result.Tuple<number, Error>>;
|
|
856
|
+
type ResTplFn = (arg: unknown) => Result.Tuple<boolean, Error>;
|
|
857
|
+
type ResTplPromiseFn = (arg: unknown) => Promise<Result.Tuple<Date, Error>>;
|
|
858
|
+
|
|
859
|
+
type Payload1 = Result.PayloadOf<ResTpl>; // string
|
|
860
|
+
type Payload2 = Result.PayloadOf<ResTplPromise>; // number
|
|
861
|
+
type Payload3 = Result.PayloadOf<ResTplFn>; // boolean
|
|
862
|
+
type Payload4 = Result.PayloadOf<ResTplPromiseFn>; // Date
|
|
863
|
+
```
|
|
864
|
+
|
|
841
865
|
---
|
|
842
866
|
|
|
843
867
|
## `@reykjavik/webtools/SiteImprove`
|
|
@@ -1192,11 +1216,15 @@ const myStyle = style({
|
|
|
1192
1216
|
### `vanillaVars`
|
|
1193
1217
|
|
|
1194
1218
|
**Syntax:**
|
|
1195
|
-
`` vanillaVars(...varNames: Array<T>): Record <`var${Capitalize<T>}`, string> ``
|
|
1219
|
+
`` vanillaVars(...varNames: Array<T>): Record <`var${Capitalize<T>}`, string> & { setVars: (Partial<Record<`var${Capitalize<T>}`, unknown>>) => string} ``
|
|
1196
1220
|
|
|
1197
1221
|
Returns an object with privately scoped CSS variables props. Pass them around
|
|
1198
1222
|
and use them in your CSS.
|
|
1199
1223
|
|
|
1224
|
+
The object also has a `setVars` method for generating a CSS string that sets
|
|
1225
|
+
all or some of the variables in CSS, without offending VSCode's CSS syntax
|
|
1226
|
+
parser too much.
|
|
1227
|
+
|
|
1200
1228
|
```ts
|
|
1201
1229
|
// MyComponent.css.ts
|
|
1202
1230
|
import {
|
package/errorhandling.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type ResultTuple<T, E extends Error = Error> = [error: undefined, result:
|
|
|
51
51
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttupleobj
|
|
52
52
|
*/
|
|
53
53
|
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
54
|
+
declare function Fail<E extends Error = Error>(e: E): FailResult<E>;
|
|
55
|
+
declare function Fail<E extends Error = Error>(e: unknown): FailResult<E>;
|
|
54
56
|
/**
|
|
55
57
|
* Error handling utility that wraps a promise or a callback function.
|
|
56
58
|
*
|
|
@@ -82,7 +84,7 @@ export declare const Result: {
|
|
|
82
84
|
*
|
|
83
85
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
84
86
|
*/
|
|
85
|
-
Fail:
|
|
87
|
+
Fail: typeof Fail;
|
|
86
88
|
catch: typeof catch_;
|
|
87
89
|
ify: typeof catch_;
|
|
88
90
|
/**
|
|
@@ -106,5 +108,12 @@ export declare namespace Result {
|
|
|
106
108
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
109
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
110
|
type FailObj<E extends Error> = FailResult<E>;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
113
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
114
|
+
*
|
|
115
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
116
|
+
*/
|
|
117
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
118
|
}
|
|
110
119
|
export {};
|
package/errorhandling.js
CHANGED
|
@@ -48,12 +48,12 @@ const Success = (result) => {
|
|
|
48
48
|
return tuple;
|
|
49
49
|
};
|
|
50
50
|
/*#__NO_SIDE_EFFECTS__*/
|
|
51
|
-
|
|
51
|
+
function Fail(e) {
|
|
52
52
|
const tuple = [(0, exports.asError)(e)];
|
|
53
53
|
tuple.error = tuple[0];
|
|
54
54
|
tuple.mapTo = () => tuple;
|
|
55
55
|
return tuple;
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
57
|
/*#__NO_SIDE_EFFECTS__*/
|
|
58
58
|
function catch_(something) {
|
|
59
59
|
if (something instanceof Promise) {
|
package/esm/errorhandling.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type ResultTuple<T, E extends Error = Error> = [error: undefined, result:
|
|
|
51
51
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resulttupleobj
|
|
52
52
|
*/
|
|
53
53
|
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
54
|
+
declare function Fail<E extends Error = Error>(e: E): FailResult<E>;
|
|
55
|
+
declare function Fail<E extends Error = Error>(e: unknown): FailResult<E>;
|
|
54
56
|
/**
|
|
55
57
|
* Error handling utility that wraps a promise or a callback function.
|
|
56
58
|
*
|
|
@@ -82,7 +84,7 @@ export declare const Result: {
|
|
|
82
84
|
*
|
|
83
85
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#resultsfail
|
|
84
86
|
*/
|
|
85
|
-
Fail:
|
|
87
|
+
Fail: typeof Fail;
|
|
86
88
|
catch: typeof catch_;
|
|
87
89
|
ify: typeof catch_;
|
|
88
90
|
/**
|
|
@@ -106,5 +108,12 @@ export declare namespace Result {
|
|
|
106
108
|
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
107
109
|
type SuccessObj<T> = SuccessResult<T>;
|
|
108
110
|
type FailObj<E extends Error> = FailResult<E>;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the successful payload type `T` from a `Result.Tuple<T>`-like
|
|
113
|
+
* type, a `Promise` of such type, or a function returning either of those.
|
|
114
|
+
*
|
|
115
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#type-resultpayloadof
|
|
116
|
+
*/
|
|
117
|
+
type PayloadOf<T extends ResultTuple<unknown> | Promise<ResultTuple<unknown>> | ((...args: Array<any>) => ResultTuple<unknown> | Promise<ResultTuple<unknown>>)> = T extends [undefined, infer P] | Promise<ResultTuple<infer P>> | ((...args: Array<any>) => ResultTuple<infer P> | Promise<ResultTuple<infer P>>) ? P : never;
|
|
109
118
|
}
|
|
110
119
|
export {};
|
package/esm/errorhandling.js
CHANGED
|
@@ -43,12 +43,12 @@ const Success = (result) => {
|
|
|
43
43
|
return tuple;
|
|
44
44
|
};
|
|
45
45
|
/*#__NO_SIDE_EFFECTS__*/
|
|
46
|
-
|
|
46
|
+
function Fail(e) {
|
|
47
47
|
const tuple = [asError(e)];
|
|
48
48
|
tuple.error = tuple[0];
|
|
49
49
|
tuple.mapTo = () => tuple;
|
|
50
50
|
return tuple;
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
/*#__NO_SIDE_EFFECTS__*/
|
|
53
53
|
function catch_(something) {
|
|
54
54
|
if (something instanceof Promise) {
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare function vanillaClass(debugId: string, css: string | ClassNameCal
|
|
|
35
35
|
* Returns an object with privately scoped CSS variables props.
|
|
36
36
|
* Pass them around and use them in your CSS.
|
|
37
37
|
*
|
|
38
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#
|
|
38
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillavars
|
|
39
39
|
*/
|
|
40
40
|
export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string> & {
|
|
41
41
|
/** Allows initializing all or some of the variables in CSS, without offending VSCode's CSS syntax parser too much. */
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -31,7 +31,7 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
31
31
|
* Returns an object with privately scoped CSS variables props.
|
|
32
32
|
* Pass them around and use them in your CSS.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillavars
|
|
35
35
|
*/
|
|
36
36
|
export const vanillaVars = (...varNames) => {
|
|
37
37
|
const id = vanillaClass(``);
|
package/package.json
CHANGED
package/vanillaExtract.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare function vanillaClass(debugId: string, css: string | ClassNameCal
|
|
|
35
35
|
* Returns an object with privately scoped CSS variables props.
|
|
36
36
|
* Pass them around and use them in your CSS.
|
|
37
37
|
*
|
|
38
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#
|
|
38
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillavars
|
|
39
39
|
*/
|
|
40
40
|
export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string> & {
|
|
41
41
|
/** Allows initializing all or some of the variables in CSS, without offending VSCode's CSS syntax parser too much. */
|
package/vanillaExtract.js
CHANGED
|
@@ -37,7 +37,7 @@ function vanillaClass(cssOrDebugId, css) {
|
|
|
37
37
|
* Returns an object with privately scoped CSS variables props.
|
|
38
38
|
* Pass them around and use them in your CSS.
|
|
39
39
|
*
|
|
40
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#
|
|
40
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.3/README.md#vanillavars
|
|
41
41
|
*/
|
|
42
42
|
const vanillaVars = (...varNames) => {
|
|
43
43
|
const id = vanillaClass(``);
|