@reykjavik/webtools 0.1.37 → 0.2.1

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CookieHubConsent.d.ts +2 -2
  3. package/CookieHubConsent.js +2 -2
  4. package/README.md +9 -5
  5. package/SiteImprove.d.ts +3 -3
  6. package/SiteImprove.js +3 -3
  7. package/async.d.ts +2 -2
  8. package/async.js +1 -1
  9. package/errorhandling.d.ts +12 -12
  10. package/errorhandling.js +8 -8
  11. package/esm/CookieHubConsent.d.ts +2 -2
  12. package/esm/CookieHubConsent.js +2 -2
  13. package/esm/SiteImprove.d.ts +3 -3
  14. package/esm/SiteImprove.js +3 -3
  15. package/esm/async.d.ts +2 -2
  16. package/esm/async.js +1 -1
  17. package/esm/errorhandling.d.ts +12 -12
  18. package/esm/errorhandling.js +8 -8
  19. package/esm/http.d.ts +5 -5
  20. package/esm/http.js +4 -4
  21. package/esm/index.d.ts +2 -3
  22. package/esm/next/http.d.ts +2 -2
  23. package/esm/next/http.js +3 -3
  24. package/{remix → esm/react-router}/Wait.d.ts +2 -2
  25. package/esm/{remix → react-router}/Wait.js +2 -2
  26. package/esm/{remix → react-router}/http.d.ts +1 -1
  27. package/esm/{remix → react-router}/http.js +1 -1
  28. package/esm/vanillaExtract.d.ts +3 -132
  29. package/esm/vanillaExtract.js +2 -67
  30. package/http.d.ts +5 -5
  31. package/http.js +4 -4
  32. package/index.d.ts +2 -3
  33. package/next/http.d.ts +2 -2
  34. package/next/http.js +3 -3
  35. package/package.json +13 -17
  36. package/{esm/remix → react-router}/Wait.d.ts +2 -2
  37. package/{remix → react-router}/Wait.js +3 -3
  38. package/{remix → react-router}/http.d.ts +1 -1
  39. package/{remix → react-router}/http.js +1 -1
  40. package/vanillaExtract.d.ts +3 -132
  41. package/vanillaExtract.js +3 -70
  42. package/esm/next/SiteImprove.d.ts +0 -9
  43. package/esm/next/SiteImprove.js +0 -7
  44. package/next/SiteImprove.d.ts +0 -9
  45. package/next/SiteImprove.js +0 -10
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.2.1
8
+
9
+ _2024-12-17_
10
+
11
+ - fix: Make typing of failed ResultTuple/ResultTupleObj less ambiguous
12
+
13
+ ## 0.2.0
14
+
15
+ _2024-12-12_
16
+
17
+ - feat: Add `@reykjavik/webtools/react-router/*` (previously `/remix/*`)
18
+ - **BREAKING** feat: Remove all `@reykjavik/webtools/react-router/*` modules
19
+ - **BREAKING** feat: Bump `pkg.engines.node` version to >=20
20
+ - **BREAKING** feat: Remove `@reykjavik/webtools/next/SiteImprove` (deprecated
21
+ module)
22
+ - **BREAKING** feat: Remove deprecated exports `vanillaNest` and
23
+ `vanillaClassNested` from `@reykjavik/webtools/vanillaExtract`
24
+
7
25
  ## 0.1.37
8
26
 
9
27
  _2024-10-23_
@@ -218,14 +218,14 @@ export type CookieHubProviderProps = EitherObj<{
218
218
  * management script and sets up a React state object with the relevant user
219
219
  * consent flags.
220
220
  *
221
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#cookiehubprovider-component
221
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
222
222
  */
223
223
  export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
224
224
  /**
225
225
  * Returns up-to-date cookie consent flags. For use in React components or hook
226
226
  * functions.
227
227
  *
228
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#usecookiehubconsent
228
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
229
229
  */
230
230
  export declare const useCookieHubConsent: () => Partial<CookieHubContextState['consent']>;
231
231
  export {};
@@ -61,7 +61,7 @@ const moveCookiehubScriptInDomTree = () => {
61
61
  * management script and sets up a React state object with the relevant user
62
62
  * consent flags.
63
63
  *
64
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#cookiehubprovider-component
64
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
65
65
  */
66
66
  const CookieHubProvider = (props) => {
67
67
  const [state, setState] = (0, react_1.useState)(initialConsentState);
@@ -134,7 +134,7 @@ exports.CookieHubProvider = CookieHubProvider;
134
134
  * Returns up-to-date cookie consent flags. For use in React components or hook
135
135
  * functions.
136
136
  *
137
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#usecookiehubconsent
137
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
138
138
  */
139
139
  const useCookieHubConsent = () => { var _a; return ((_a = (0, react_1.useContext)(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
140
140
  exports.useCookieHubConsent = useCookieHubConsent;
package/README.md CHANGED
@@ -51,7 +51,7 @@ bun add @reykjavik/webtools
51
51
  - [`vanillaGlobal`](#vanillaglobal)
52
52
  - [`vanillaProps`](#vanillaprops)
53
53
  - [Framework Specific Tools](#framework-specific-tools)
54
- - [Remix.run Tools](#remixrun-tools)
54
+ - [React-Router Tools](#react-router-tools)
55
55
  - [Next.js Tools](#nextjs-tools)
56
56
  - [Contributing](#contributing)
57
57
  - [Changelog](#changelog)
@@ -484,7 +484,8 @@ if (myResult.error) {
484
484
 
485
485
  ### `Result.catch`
486
486
 
487
- **Syntax:** `Result.catch<T, Err>(callback: () => T): ResultTupleObj<T, Err>`
487
+ **Syntax:**
488
+ `Result.catch<T, Err>(callback: () => T): ResultTupleObj<T, Err>`
488
489
  **Syntax:**
489
490
  `Result.catch<T, Err>(promise: Promise<T>): Promise<ResultTupleObj<T, Err>>`
490
491
 
@@ -881,10 +882,13 @@ const myStyle = style({
881
882
 
882
883
  ## Framework Specific Tools
883
884
 
884
- ### Remix.run Tools
885
+ ### React-Router Tools
886
+
887
+ See [README-rr.md](./README-rr.md) for helpers and components specifically
888
+ designed for use in Remix.run projects.
885
889
 
886
- See [README-remix.md](./README-remix.md) for helpers and components
887
- specifically designed for use in Remix.run projects.
890
+ (NOTE: If you're still using [Remix.run](https://remix.run) you can install
891
+ version `"^0.1.22"` of this package.)
888
892
 
889
893
  <!-- #fragment anchors to not break older v0.1 @see links -->
890
894
 
package/SiteImprove.d.ts CHANGED
@@ -45,14 +45,14 @@ type SiteImproveCustomEvent = [
45
45
  /**
46
46
  * A small helper for tracking custom UI events and reporting them to SiteImrove.
47
47
  *
48
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimprove-helper
48
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
49
49
  */
50
50
  export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
51
51
  /**
52
52
  * A small helper for reporting to SiteImrove when the user is programmatically
53
53
  * being sent to a different URL/resource.
54
54
  *
55
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimproveoutbound-helper
55
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
56
56
  */
57
57
  export declare const pingSiteImproveOutbound: (ourl: string) => void;
58
58
  export type SiteImproveProps = EitherObj<{
@@ -94,7 +94,7 @@ export type SiteImproveProps = EitherObj<{
94
94
  * A component for loading a SiteImprove analytics script and set up page-view
95
95
  * tracking across client-side (pushState, replaceState) routing.
96
96
  *
97
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
97
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
98
98
  */
99
99
  export declare const SiteImprove: (props: SiteImproveProps) => null;
100
100
  export {};
package/SiteImprove.js CHANGED
@@ -29,7 +29,7 @@ const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic',
29
29
  /**
30
30
  * A small helper for tracking custom UI events and reporting them to SiteImrove.
31
31
  *
32
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimprove-helper
32
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
33
33
  */
34
34
  const pingSiteImprove = (category, action, label) => {
35
35
  if (process.env.NODE_ENV === 'development' &&
@@ -44,7 +44,7 @@ exports.pingSiteImprove = pingSiteImprove;
44
44
  * A small helper for reporting to SiteImrove when the user is programmatically
45
45
  * being sent to a different URL/resource.
46
46
  *
47
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimproveoutbound-helper
47
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
48
48
  */
49
49
  const pingSiteImproveOutbound = (ourl) => {
50
50
  if (process.env.NODE_ENV === 'development' &&
@@ -125,7 +125,7 @@ const loc = typeof document !== 'undefined' ? document.location : {};
125
125
  * A component for loading a SiteImprove analytics script and set up page-view
126
126
  * tracking across client-side (pushState, replaceState) routing.
127
127
  *
128
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
128
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
129
129
  */
130
130
  const SiteImprove = (props) => {
131
131
  const consented = useResolvedAnalyticsConsent(props.hasConsented);
package/async.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare const addLag: (length: number) => <T>(res: T) => Promise<T>;
14
14
  * Resolves as soon as all of the passed `promises` have resolved/settled,
15
15
  * or after `timeout` milliseconds — whichever comes first.
16
16
  *
17
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#maxwait
17
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#maxwait
18
18
  */
19
19
  export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
20
20
  export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
@@ -24,7 +24,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
24
24
  * A variation of `Promise.all()` that accepts an object with named promises
25
25
  * and returns a same-shaped object with the resolved values.
26
26
  *
27
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#promiseallobject
27
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
28
28
  */
29
29
  export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
30
30
  export {};
package/async.js CHANGED
@@ -45,7 +45,7 @@ exports.maxWait = maxWait;
45
45
  * A variation of `Promise.all()` that accepts an object with named promises
46
46
  * and returns a same-shaped object with the resolved values.
47
47
  *
48
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#promiseallobject
48
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
49
49
  */
50
50
  const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
51
51
  const keys = Object.keys(promisesMap);
@@ -2,7 +2,7 @@
2
2
  * Error subclass for thrown values that got cought and turned into an actual
3
3
  * Error, with the thrown value as the `payload` property.
4
4
  *
5
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
5
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
6
6
  */
7
7
  export declare class ErrorFromPayload extends Error {
8
8
  payload?: unknown;
@@ -17,28 +17,28 @@ export declare class ErrorFromPayload extends Error {
17
17
  * something else it is wrapped in a new `ErrorFromPayload` instance, and the
18
18
  * original value is stored in a `payload`
19
19
  *
20
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
20
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
21
21
  */
22
22
  export declare const asError: (maybeError: unknown) => ErrorFromPayload;
23
23
  type SuccessResult<T> = [error: undefined, result: T] & {
24
24
  error?: undefined;
25
25
  result: T;
26
26
  };
27
- type FailResult<E extends Error> = [error: E] & {
27
+ type FailResult<E extends Error> = [error: E, result?: undefined] & {
28
28
  error: E;
29
29
  result?: undefined;
30
30
  };
31
31
  /**
32
32
  * Simple bare-bones discriminated tuple type for a [error, result] pair.
33
33
  *
34
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttuple
34
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttuple
35
35
  */
36
- export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E];
36
+ export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E, result?: undefined];
37
37
  /**
38
38
  * Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
39
39
  * but with named properties `error` and `result` attached for dev convenience.
40
40
  *
41
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttupleobj
41
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttupleobj
42
42
  */
43
43
  export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
44
44
  /**
@@ -50,7 +50,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
50
50
  *
51
51
  * Works on both promises and sync callback functions.
52
52
  *
53
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultcatch
53
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultcatch
54
54
  */
55
55
  declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
56
56
  declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
@@ -58,19 +58,19 @@ declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T
58
58
  * Singleton object with small methods for creating, mapping or handling
59
59
  * `ResultTupleObj` instances.
60
60
  *
61
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
61
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
62
62
  */
63
63
  export declare const Result: {
64
64
  /**
65
65
  * Factory for creating a successful `Result.TupleObj`.
66
66
  *
67
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
67
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
68
68
  */
69
69
  Success: <T>(result: T) => SuccessResult<T>;
70
70
  /**
71
71
  * Factory for creating a failed `Result.TupleObj`.
72
72
  *
73
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
73
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
74
74
  */
75
75
  Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
76
76
  catch: typeof catch_;
@@ -79,14 +79,14 @@ export declare const Result: {
79
79
  * object, applying a transformation function to the result, but retaining
80
80
  * the error as-is.
81
81
  *
82
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
82
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
83
83
  */
84
84
  map: <T_1, T2, E_1 extends Error>(result: ResultTuple<T_1, E_1>, mapFn: (resultValue: T_1) => T2) => ResultTupleObj<T2, E_1>;
85
85
  /**
86
86
  * Unwraps a discriminated [error, result] `Result.Tuple`-like object
87
87
  * and throws if there's an error, but returns the result otherwise.
88
88
  *
89
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
89
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
90
90
  */
91
91
  throw: <T_2>(result: ResultTuple<T_2, Error>) => T_2;
92
92
  };
package/errorhandling.js CHANGED
@@ -5,7 +5,7 @@ exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
5
5
  * Error subclass for thrown values that got cought and turned into an actual
6
6
  * Error, with the thrown value as the `payload` property.
7
7
  *
8
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
8
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
9
9
  */
10
10
  class ErrorFromPayload extends Error {
11
11
  constructor(payload) {
@@ -27,7 +27,7 @@ exports.ErrorFromPayload = ErrorFromPayload;
27
27
  * something else it is wrapped in a new `ErrorFromPayload` instance, and the
28
28
  * original value is stored in a `payload`
29
29
  *
30
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
30
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
31
31
  */
32
32
  const asError = (maybeError) => {
33
33
  if (maybeError instanceof Error) {
@@ -48,7 +48,7 @@ const Fail = (e) => {
48
48
  };
49
49
  function catch_(something) {
50
50
  if (something instanceof Promise) {
51
- return something.then((result) => Success(result), (e) => Fail(e));
51
+ return something.then(Success, (e) => Fail(e));
52
52
  }
53
53
  try {
54
54
  return Success(something());
@@ -61,19 +61,19 @@ function catch_(something) {
61
61
  * Singleton object with small methods for creating, mapping or handling
62
62
  * `ResultTupleObj` instances.
63
63
  *
64
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
64
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
65
65
  */
66
66
  exports.Result = {
67
67
  /**
68
68
  * Factory for creating a successful `Result.TupleObj`.
69
69
  *
70
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
70
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
71
71
  */
72
72
  Success,
73
73
  /**
74
74
  * Factory for creating a failed `Result.TupleObj`.
75
75
  *
76
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
76
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
77
77
  */
78
78
  Fail,
79
79
  // NOTE: The JSDoc must be placed above the `catch_` function above.
@@ -83,7 +83,7 @@ exports.Result = {
83
83
  * object, applying a transformation function to the result, but retaining
84
84
  * the error as-is.
85
85
  *
86
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
86
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
87
87
  */
88
88
  map: (result, mapFn) => {
89
89
  const [error, resultValue] = result;
@@ -96,7 +96,7 @@ exports.Result = {
96
96
  * Unwraps a discriminated [error, result] `Result.Tuple`-like object
97
97
  * and throws if there's an error, but returns the result otherwise.
98
98
  *
99
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
99
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
100
100
  */
101
101
  throw: (result) => {
102
102
  if (result[0]) {
@@ -218,14 +218,14 @@ export type CookieHubProviderProps = EitherObj<{
218
218
  * management script and sets up a React state object with the relevant user
219
219
  * consent flags.
220
220
  *
221
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#cookiehubprovider-component
221
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
222
222
  */
223
223
  export declare const CookieHubProvider: (props: CookieHubProviderProps) => React.JSX.Element;
224
224
  /**
225
225
  * Returns up-to-date cookie consent flags. For use in React components or hook
226
226
  * functions.
227
227
  *
228
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#usecookiehubconsent
228
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
229
229
  */
230
230
  export declare const useCookieHubConsent: () => Partial<CookieHubContextState['consent']>;
231
231
  export {};
@@ -35,7 +35,7 @@ const moveCookiehubScriptInDomTree = () => {
35
35
  * management script and sets up a React state object with the relevant user
36
36
  * consent flags.
37
37
  *
38
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#cookiehubprovider-component
38
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cookiehubprovider-component
39
39
  */
40
40
  export const CookieHubProvider = (props) => {
41
41
  const [state, setState] = useState(initialConsentState);
@@ -107,6 +107,6 @@ export const CookieHubProvider = (props) => {
107
107
  * Returns up-to-date cookie consent flags. For use in React components or hook
108
108
  * functions.
109
109
  *
110
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#usecookiehubconsent
110
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
111
111
  */
112
112
  export const useCookieHubConsent = () => { var _a; return ((_a = useContext(CookieHubContext)) === null || _a === void 0 ? void 0 : _a.consent) || {}; };
@@ -45,14 +45,14 @@ type SiteImproveCustomEvent = [
45
45
  /**
46
46
  * A small helper for tracking custom UI events and reporting them to SiteImrove.
47
47
  *
48
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimprove-helper
48
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
49
49
  */
50
50
  export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
51
51
  /**
52
52
  * A small helper for reporting to SiteImrove when the user is programmatically
53
53
  * being sent to a different URL/resource.
54
54
  *
55
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimproveoutbound-helper
55
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
56
56
  */
57
57
  export declare const pingSiteImproveOutbound: (ourl: string) => void;
58
58
  export type SiteImproveProps = EitherObj<{
@@ -94,7 +94,7 @@ export type SiteImproveProps = EitherObj<{
94
94
  * A component for loading a SiteImprove analytics script and set up page-view
95
95
  * tracking across client-side (pushState, replaceState) routing.
96
96
  *
97
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
97
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
98
98
  */
99
99
  export declare const SiteImprove: (props: SiteImproveProps) => null;
100
100
  export {};
@@ -26,7 +26,7 @@ const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic',
26
26
  /**
27
27
  * A small helper for tracking custom UI events and reporting them to SiteImrove.
28
28
  *
29
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimprove-helper
29
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimprove-helper
30
30
  */
31
31
  export const pingSiteImprove = (category, action, label) => {
32
32
  if (process.env.NODE_ENV === 'development' &&
@@ -40,7 +40,7 @@ export const pingSiteImprove = (category, action, label) => {
40
40
  * A small helper for reporting to SiteImrove when the user is programmatically
41
41
  * being sent to a different URL/resource.
42
42
  *
43
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#pingsiteimproveoutbound-helper
43
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#pingsiteimproveoutbound-helper
44
44
  */
45
45
  export const pingSiteImproveOutbound = (ourl) => {
46
46
  if (process.env.NODE_ENV === 'development' &&
@@ -120,7 +120,7 @@ const loc = typeof document !== 'undefined' ? document.location : {};
120
120
  * A component for loading a SiteImprove analytics script and set up page-view
121
121
  * tracking across client-side (pushState, replaceState) routing.
122
122
  *
123
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
123
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#siteimprove-component
124
124
  */
125
125
  export const SiteImprove = (props) => {
126
126
  const consented = useResolvedAnalyticsConsent(props.hasConsented);
package/esm/async.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare const addLag: (length: number) => <T>(res: T) => Promise<T>;
14
14
  * Resolves as soon as all of the passed `promises` have resolved/settled,
15
15
  * or after `timeout` milliseconds — whichever comes first.
16
16
  *
17
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#maxwait
17
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#maxwait
18
18
  */
19
19
  export declare function maxWait(timeout: number, promises: Array<unknown>): Promise<void>;
20
20
  export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, promises: PromiseMap): Promise<{
@@ -24,7 +24,7 @@ export declare function maxWait<PromiseMap extends PlainObj>(timeout: number, pr
24
24
  * A variation of `Promise.all()` that accepts an object with named promises
25
25
  * and returns a same-shaped object with the resolved values.
26
26
  *
27
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#promiseallobject
27
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
28
28
  */
29
29
  export declare const promiseAllObject: <T extends PlainObj>(promisesMap: T) => Promise<{ -readonly [K in keyof T]: Awaited<T[K]>; }>;
30
30
  export {};
package/esm/async.js CHANGED
@@ -39,7 +39,7 @@ export function maxWait(timeout, promises) {
39
39
  * A variation of `Promise.all()` that accepts an object with named promises
40
40
  * and returns a same-shaped object with the resolved values.
41
41
  *
42
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#promiseallobject
42
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
43
43
  */
44
44
  export const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
45
45
  const keys = Object.keys(promisesMap);
@@ -2,7 +2,7 @@
2
2
  * Error subclass for thrown values that got cought and turned into an actual
3
3
  * Error, with the thrown value as the `payload` property.
4
4
  *
5
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
5
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
6
6
  */
7
7
  export declare class ErrorFromPayload extends Error {
8
8
  payload?: unknown;
@@ -17,28 +17,28 @@ export declare class ErrorFromPayload extends Error {
17
17
  * something else it is wrapped in a new `ErrorFromPayload` instance, and the
18
18
  * original value is stored in a `payload`
19
19
  *
20
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
20
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
21
21
  */
22
22
  export declare const asError: (maybeError: unknown) => ErrorFromPayload;
23
23
  type SuccessResult<T> = [error: undefined, result: T] & {
24
24
  error?: undefined;
25
25
  result: T;
26
26
  };
27
- type FailResult<E extends Error> = [error: E] & {
27
+ type FailResult<E extends Error> = [error: E, result?: undefined] & {
28
28
  error: E;
29
29
  result?: undefined;
30
30
  };
31
31
  /**
32
32
  * Simple bare-bones discriminated tuple type for a [error, result] pair.
33
33
  *
34
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttuple
34
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttuple
35
35
  */
36
- export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E];
36
+ export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E, result?: undefined];
37
37
  /**
38
38
  * Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
39
39
  * but with named properties `error` and `result` attached for dev convenience.
40
40
  *
41
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttupleobj
41
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-resulttupleobj
42
42
  */
43
43
  export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
44
44
  /**
@@ -50,7 +50,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
50
50
  *
51
51
  * Works on both promises and sync callback functions.
52
52
  *
53
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultcatch
53
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultcatch
54
54
  */
55
55
  declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
56
56
  declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
@@ -58,19 +58,19 @@ declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T
58
58
  * Singleton object with small methods for creating, mapping or handling
59
59
  * `ResultTupleObj` instances.
60
60
  *
61
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
61
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
62
62
  */
63
63
  export declare const Result: {
64
64
  /**
65
65
  * Factory for creating a successful `Result.TupleObj`.
66
66
  *
67
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
67
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
68
68
  */
69
69
  Success: <T>(result: T) => SuccessResult<T>;
70
70
  /**
71
71
  * Factory for creating a failed `Result.TupleObj`.
72
72
  *
73
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
73
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
74
74
  */
75
75
  Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
76
76
  catch: typeof catch_;
@@ -79,14 +79,14 @@ export declare const Result: {
79
79
  * object, applying a transformation function to the result, but retaining
80
80
  * the error as-is.
81
81
  *
82
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
82
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
83
83
  */
84
84
  map: <T_1, T2, E_1 extends Error>(result: ResultTuple<T_1, E_1>, mapFn: (resultValue: T_1) => T2) => ResultTupleObj<T2, E_1>;
85
85
  /**
86
86
  * Unwraps a discriminated [error, result] `Result.Tuple`-like object
87
87
  * and throws if there's an error, but returns the result otherwise.
88
88
  *
89
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
89
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
90
90
  */
91
91
  throw: <T_2>(result: ResultTuple<T_2, Error>) => T_2;
92
92
  };
@@ -2,7 +2,7 @@
2
2
  * Error subclass for thrown values that got cought and turned into an actual
3
3
  * Error, with the thrown value as the `payload` property.
4
4
  *
5
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
5
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
6
6
  */
7
7
  export class ErrorFromPayload extends Error {
8
8
  constructor(payload) {
@@ -23,7 +23,7 @@ export class ErrorFromPayload extends Error {
23
23
  * something else it is wrapped in a new `ErrorFromPayload` instance, and the
24
24
  * original value is stored in a `payload`
25
25
  *
26
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
26
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
27
27
  */
28
28
  export const asError = (maybeError) => {
29
29
  if (maybeError instanceof Error) {
@@ -43,7 +43,7 @@ const Fail = (e) => {
43
43
  };
44
44
  function catch_(something) {
45
45
  if (something instanceof Promise) {
46
- return something.then((result) => Success(result), (e) => Fail(e));
46
+ return something.then(Success, (e) => Fail(e));
47
47
  }
48
48
  try {
49
49
  return Success(something());
@@ -56,19 +56,19 @@ function catch_(something) {
56
56
  * Singleton object with small methods for creating, mapping or handling
57
57
  * `ResultTupleObj` instances.
58
58
  *
59
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
59
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#result-singleton
60
60
  */
61
61
  export const Result = {
62
62
  /**
63
63
  * Factory for creating a successful `Result.TupleObj`.
64
64
  *
65
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
65
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsuccess
66
66
  */
67
67
  Success,
68
68
  /**
69
69
  * Factory for creating a failed `Result.TupleObj`.
70
70
  *
71
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
71
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultsfail
72
72
  */
73
73
  Fail,
74
74
  // NOTE: The JSDoc must be placed above the `catch_` function above.
@@ -78,7 +78,7 @@ export const Result = {
78
78
  * object, applying a transformation function to the result, but retaining
79
79
  * the error as-is.
80
80
  *
81
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
81
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
82
82
  */
83
83
  map: (result, mapFn) => {
84
84
  const [error, resultValue] = result;
@@ -91,7 +91,7 @@ export const Result = {
91
91
  * Unwraps a discriminated [error, result] `Result.Tuple`-like object
92
92
  * and throws if there's an error, but returns the result otherwise.
93
93
  *
94
- * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
94
+ * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
95
95
  */
96
96
  throw: (result) => {
97
97
  if (result[0]) {