@reykjavik/webtools 0.2.2 → 0.2.4
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 +15 -0
- package/CookieHubConsent.d.ts +1 -1
- package/CookieHubConsent.js +17 -7
- package/README.md +38 -2
- package/async.js +6 -2
- package/errorhandling.d.ts +4 -2
- package/errorhandling.js +21 -1
- package/esm/CookieHubConsent.d.ts +1 -1
- package/esm/async.js +4 -0
- package/esm/errorhandling.d.ts +4 -2
- package/esm/errorhandling.js +21 -1
- package/esm/fixIcelandicLocale.privates.d.ts +16 -42
- package/esm/fixIcelandicLocale.privates.js +3 -3
- package/esm/http.d.ts +0 -1
- package/esm/http.js +6 -1
- package/esm/next/http.d.ts +2 -3
- package/esm/next/http.js +3 -0
- package/esm/react-router/http.js +1 -0
- package/fixIcelandicLocale.privates.d.ts +16 -42
- package/fixIcelandicLocale.privates.js +3 -3
- package/http.d.ts +0 -1
- package/http.js +6 -1
- package/next/http.d.ts +2 -3
- package/next/http.js +3 -0
- package/package.json +2 -2
- package/react-router/Wait.js +17 -7
- package/react-router/http.js +1 -0
- package/vanillaExtract.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.2.4
|
|
8
|
+
|
|
9
|
+
_2025-05-09_
|
|
10
|
+
|
|
11
|
+
- perf: Add `#__NO_SIDE_EFFECTS__` compiler notation to selected functions
|
|
12
|
+
|
|
13
|
+
## 0.2.3
|
|
14
|
+
|
|
15
|
+
_2025-03-31_
|
|
16
|
+
|
|
17
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
18
|
+
- feat: Add a `.mapTo(fn)` method to `ResultTupleObj`s
|
|
19
|
+
- fix: `Result.map` does not catch errors thrown by the mapping function
|
|
20
|
+
- docs: Fix minor error in README code example
|
|
21
|
+
|
|
7
22
|
## 0.2.2
|
|
8
23
|
|
|
9
24
|
_2024-12-19_
|
package/CookieHubConsent.d.ts
CHANGED
|
@@ -229,5 +229,5 @@ export declare const CookieHubProvider: (props: CookieHubProviderProps) => React
|
|
|
229
229
|
*
|
|
230
230
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
231
231
|
*/
|
|
232
|
-
export declare const useCookieHubConsent: () => Partial<CookieHubContextState[
|
|
232
|
+
export declare const useCookieHubConsent: () => Partial<CookieHubContextState["consent"]>;
|
|
233
233
|
export {};
|
package/CookieHubConsent.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.useCookieHubConsent = exports.CookieHubProvider = void 0;
|
|
27
37
|
const react_1 = __importStar(require("react"));
|
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ bun add @reykjavik/webtools
|
|
|
34
34
|
- [`Result` Singleton](#result-singleton)
|
|
35
35
|
- [Type `ResultTuple`](#type-resulttuple)
|
|
36
36
|
- [Type `ResultTupleObj`](#type-resulttupleobj)
|
|
37
|
+
- [Type `ResultTupleObj.mapTo`](#type-resulttupleobjmapto)
|
|
37
38
|
- [`Result.catch`](#resultcatch)
|
|
38
39
|
- [`Result.map`](#resultmap)
|
|
39
40
|
- [`Result.Success`](#resultsuccess)
|
|
@@ -456,10 +457,12 @@ if (error) {
|
|
|
456
457
|
Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
|
|
457
458
|
but with named properties `error` and `result` attached for dev convenience.
|
|
458
459
|
|
|
460
|
+
It also has a `.mapTo` method ([see below](#type-resulttupleobjmapto)).
|
|
461
|
+
|
|
459
462
|
```ts
|
|
460
|
-
import { type
|
|
463
|
+
import { type ResultTupleObj } from '@reykjavik/webtools/errorhandling';
|
|
461
464
|
|
|
462
|
-
declare const myResult:
|
|
465
|
+
declare const myResult: ResultTupleObj<string, Error>;
|
|
463
466
|
|
|
464
467
|
const [error, result] = myResult;
|
|
465
468
|
// (One of these two is always `undefined`)
|
|
@@ -482,6 +485,39 @@ if (myResult.error) {
|
|
|
482
485
|
}
|
|
483
486
|
```
|
|
484
487
|
|
|
488
|
+
#### Type `ResultTupleObj.mapTo`
|
|
489
|
+
|
|
490
|
+
**Syntax:**
|
|
491
|
+
`ResultTupleObj.mapTo<T2, E>(mapResult: (resultValue: T) => T2): ResultTuple<T2, E>`
|
|
492
|
+
|
|
493
|
+
This convenience method allows quick mapping of the `ResultTubleOBj`'s result
|
|
494
|
+
value to a new type. The returned value is also a `ResultTubleOBj`.
|
|
495
|
+
|
|
496
|
+
(Internally this method calls [`Result.map`](#resultmap).)
|
|
497
|
+
|
|
498
|
+
```ts
|
|
499
|
+
import { type ResultTuple } from '@reykjavik/webtools/errorhandling';
|
|
500
|
+
|
|
501
|
+
declare const myResult: ResultTuple<string, Error>;
|
|
502
|
+
|
|
503
|
+
const mappedResult: ResultTupleObj<number, Error> = myResult.mapTo(
|
|
504
|
+
(result: string) => result.length
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
if (mappedRes.error) {
|
|
508
|
+
console.error(myResult.error.message);
|
|
509
|
+
} else {
|
|
510
|
+
// Here `myResult.result` is a number
|
|
511
|
+
console.log(myResult.result);
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
If the original `ResultTupleObj` is in a failed state, the mapping function is
|
|
516
|
+
not called.
|
|
517
|
+
|
|
518
|
+
If the mapping function throws an error it gets caught and turned into a
|
|
519
|
+
failed `ResultTupleObj`.
|
|
520
|
+
|
|
485
521
|
### `Result.catch`
|
|
486
522
|
|
|
487
523
|
**Syntax:**
|
package/async.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promiseAllObject = exports.
|
|
3
|
+
exports.promiseAllObject = exports.addLag = exports.sleep = void 0;
|
|
4
|
+
exports.maxWait = maxWait;
|
|
4
5
|
/**
|
|
5
6
|
* Simple sleep function. Returns a promise that resolves after `length`
|
|
6
7
|
* milliseconds.
|
|
7
8
|
*/
|
|
9
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
8
10
|
const sleep = (length) => new Promise((resolve) => setTimeout(resolve, length));
|
|
9
11
|
exports.sleep = sleep;
|
|
10
12
|
/**
|
|
11
13
|
* Returns a function that adds lag/delay to a promise chain,
|
|
12
14
|
* passing the promise payload through.
|
|
13
15
|
*/
|
|
16
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
14
17
|
const addLag = (length) => (res) => (0, exports.sleep)(length).then(() => res);
|
|
15
18
|
exports.addLag = addLag;
|
|
19
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
16
20
|
function maxWait(timeout, promises) {
|
|
17
21
|
if (Array.isArray(promises)) {
|
|
18
22
|
return Promise.race([
|
|
@@ -38,7 +42,6 @@ function maxWait(timeout, promises) {
|
|
|
38
42
|
return Promise.resolve().then(() => ({ ...retObj }));
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
|
-
exports.maxWait = maxWait;
|
|
42
45
|
// ---------------------------------------------------------------------------
|
|
43
46
|
// Adapted from https://github.com/marcelowa/promise-all-properties
|
|
44
47
|
/**
|
|
@@ -47,6 +50,7 @@ exports.maxWait = maxWait;
|
|
|
47
50
|
*
|
|
48
51
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
49
52
|
*/
|
|
53
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
50
54
|
const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
51
55
|
const keys = Object.keys(promisesMap);
|
|
52
56
|
const resolvedMap = {};
|
package/errorhandling.d.ts
CHANGED
|
@@ -23,10 +23,12 @@ 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
|
+
mapTo: <T2, E extends Error = Error>(fn: (result: T) => T2) => ResultTupleObj<T2, E>;
|
|
26
27
|
};
|
|
27
28
|
type FailResult<E extends Error> = [error: E, result?: undefined] & {
|
|
28
29
|
error: E;
|
|
29
30
|
result?: undefined;
|
|
31
|
+
mapTo: () => FailResult<E>;
|
|
30
32
|
};
|
|
31
33
|
/**
|
|
32
34
|
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
@@ -81,14 +83,14 @@ export declare const Result: {
|
|
|
81
83
|
*
|
|
82
84
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
83
85
|
*/
|
|
84
|
-
map: <
|
|
86
|
+
map: <T, T2, E extends Error>(result: ResultTuple<T, E>, mapFn: (resultValue: T) => T2) => ResultTupleObj<T2, E>;
|
|
85
87
|
/**
|
|
86
88
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
87
89
|
* and throws if there's an error, but returns the result otherwise.
|
|
88
90
|
*
|
|
89
91
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
90
92
|
*/
|
|
91
|
-
throw: <
|
|
93
|
+
throw: <T>(result: ResultTuple<T>) => T;
|
|
92
94
|
};
|
|
93
95
|
export declare namespace Result {
|
|
94
96
|
type Tuple<T, E extends Error = Error> = ResultTuple<T, E>;
|
package/errorhandling.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
9
9
|
*/
|
|
10
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
10
11
|
class ErrorFromPayload extends Error {
|
|
11
12
|
constructor(payload) {
|
|
12
13
|
if (process.env.NODE_ENV !== 'production' && payload instanceof Error) {
|
|
@@ -29,6 +30,7 @@ exports.ErrorFromPayload = ErrorFromPayload;
|
|
|
29
30
|
*
|
|
30
31
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
31
32
|
*/
|
|
33
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
32
34
|
const asError = (maybeError) => {
|
|
33
35
|
if (maybeError instanceof Error) {
|
|
34
36
|
return maybeError;
|
|
@@ -36,16 +38,23 @@ const asError = (maybeError) => {
|
|
|
36
38
|
return new ErrorFromPayload(maybeError);
|
|
37
39
|
};
|
|
38
40
|
exports.asError = asError;
|
|
41
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
39
42
|
const Success = (result) => {
|
|
40
43
|
const tuple = [undefined, result];
|
|
41
44
|
tuple.result = result;
|
|
45
|
+
tuple.mapTo = (fn) =>
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
47
|
+
map(tuple, fn);
|
|
42
48
|
return tuple;
|
|
43
49
|
};
|
|
50
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
44
51
|
const Fail = (e) => {
|
|
45
52
|
const tuple = [(0, exports.asError)(e)];
|
|
46
53
|
tuple.error = tuple[0];
|
|
54
|
+
tuple.mapTo = () => tuple;
|
|
47
55
|
return tuple;
|
|
48
56
|
};
|
|
57
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
49
58
|
function catch_(something) {
|
|
50
59
|
if (something instanceof Promise) {
|
|
51
60
|
return something.then(Success, (e) => Fail(e));
|
|
@@ -57,6 +66,15 @@ function catch_(something) {
|
|
|
57
66
|
return Fail(e);
|
|
58
67
|
}
|
|
59
68
|
}
|
|
69
|
+
const map = (result,
|
|
70
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
71
|
+
mapFn) => {
|
|
72
|
+
const [error, resultValue] = result;
|
|
73
|
+
if (error) {
|
|
74
|
+
return Fail(error);
|
|
75
|
+
}
|
|
76
|
+
return catch_(() => mapFn(resultValue));
|
|
77
|
+
};
|
|
60
78
|
/**
|
|
61
79
|
* Singleton object with small methods for creating, mapping or handling
|
|
62
80
|
* `ResultTupleObj` instances.
|
|
@@ -85,12 +103,13 @@ exports.Result = {
|
|
|
85
103
|
*
|
|
86
104
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
87
105
|
*/
|
|
106
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
88
107
|
map: (result, mapFn) => {
|
|
89
108
|
const [error, resultValue] = result;
|
|
90
109
|
if (error) {
|
|
91
110
|
return Fail(error);
|
|
92
111
|
}
|
|
93
|
-
return
|
|
112
|
+
return catch_(() => mapFn(resultValue));
|
|
94
113
|
},
|
|
95
114
|
/**
|
|
96
115
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
@@ -98,6 +117,7 @@ exports.Result = {
|
|
|
98
117
|
*
|
|
99
118
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
100
119
|
*/
|
|
120
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
101
121
|
throw: (result) => {
|
|
102
122
|
if (result[0]) {
|
|
103
123
|
throw result[0];
|
|
@@ -229,5 +229,5 @@ export declare const CookieHubProvider: (props: CookieHubProviderProps) => React
|
|
|
229
229
|
*
|
|
230
230
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#usecookiehubconsent
|
|
231
231
|
*/
|
|
232
|
-
export declare const useCookieHubConsent: () => Partial<CookieHubContextState[
|
|
232
|
+
export declare const useCookieHubConsent: () => Partial<CookieHubContextState["consent"]>;
|
|
233
233
|
export {};
|
package/esm/async.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* Simple sleep function. Returns a promise that resolves after `length`
|
|
3
3
|
* milliseconds.
|
|
4
4
|
*/
|
|
5
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
5
6
|
export const sleep = (length) => new Promise((resolve) => setTimeout(resolve, length));
|
|
6
7
|
/**
|
|
7
8
|
* Returns a function that adds lag/delay to a promise chain,
|
|
8
9
|
* passing the promise payload through.
|
|
9
10
|
*/
|
|
11
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
10
12
|
export const addLag = (length) => (res) => sleep(length).then(() => res);
|
|
13
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
11
14
|
export function maxWait(timeout, promises) {
|
|
12
15
|
if (Array.isArray(promises)) {
|
|
13
16
|
return Promise.race([
|
|
@@ -41,6 +44,7 @@ export function maxWait(timeout, promises) {
|
|
|
41
44
|
*
|
|
42
45
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#promiseallobject
|
|
43
46
|
*/
|
|
47
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
44
48
|
export const promiseAllObject = (promisesMap) => Promise.all(Object.values(promisesMap)).then((results) => {
|
|
45
49
|
const keys = Object.keys(promisesMap);
|
|
46
50
|
const resolvedMap = {};
|
package/esm/errorhandling.d.ts
CHANGED
|
@@ -23,10 +23,12 @@ 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
|
+
mapTo: <T2, E extends Error = Error>(fn: (result: T) => T2) => ResultTupleObj<T2, E>;
|
|
26
27
|
};
|
|
27
28
|
type FailResult<E extends Error> = [error: E, result?: undefined] & {
|
|
28
29
|
error: E;
|
|
29
30
|
result?: undefined;
|
|
31
|
+
mapTo: () => FailResult<E>;
|
|
30
32
|
};
|
|
31
33
|
/**
|
|
32
34
|
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
@@ -81,14 +83,14 @@ export declare const Result: {
|
|
|
81
83
|
*
|
|
82
84
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
83
85
|
*/
|
|
84
|
-
map: <
|
|
86
|
+
map: <T, T2, E extends Error>(result: ResultTuple<T, E>, mapFn: (resultValue: T) => T2) => ResultTupleObj<T2, E>;
|
|
85
87
|
/**
|
|
86
88
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
87
89
|
* and throws if there's an error, but returns the result otherwise.
|
|
88
90
|
*
|
|
89
91
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
90
92
|
*/
|
|
91
|
-
throw: <
|
|
93
|
+
throw: <T>(result: ResultTuple<T>) => T;
|
|
92
94
|
};
|
|
93
95
|
export declare namespace Result {
|
|
94
96
|
type Tuple<T, E extends Error = Error> = ResultTuple<T, E>;
|
package/esm/errorhandling.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
6
6
|
*/
|
|
7
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
7
8
|
export class ErrorFromPayload extends Error {
|
|
8
9
|
constructor(payload) {
|
|
9
10
|
if (process.env.NODE_ENV !== 'production' && payload instanceof Error) {
|
|
@@ -25,22 +26,30 @@ export class ErrorFromPayload extends Error {
|
|
|
25
26
|
*
|
|
26
27
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
27
28
|
*/
|
|
29
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
28
30
|
export const asError = (maybeError) => {
|
|
29
31
|
if (maybeError instanceof Error) {
|
|
30
32
|
return maybeError;
|
|
31
33
|
}
|
|
32
34
|
return new ErrorFromPayload(maybeError);
|
|
33
35
|
};
|
|
36
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
34
37
|
const Success = (result) => {
|
|
35
38
|
const tuple = [undefined, result];
|
|
36
39
|
tuple.result = result;
|
|
40
|
+
tuple.mapTo = (fn) =>
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
42
|
+
map(tuple, fn);
|
|
37
43
|
return tuple;
|
|
38
44
|
};
|
|
45
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
39
46
|
const Fail = (e) => {
|
|
40
47
|
const tuple = [asError(e)];
|
|
41
48
|
tuple.error = tuple[0];
|
|
49
|
+
tuple.mapTo = () => tuple;
|
|
42
50
|
return tuple;
|
|
43
51
|
};
|
|
52
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
44
53
|
function catch_(something) {
|
|
45
54
|
if (something instanceof Promise) {
|
|
46
55
|
return something.then(Success, (e) => Fail(e));
|
|
@@ -52,6 +61,15 @@ function catch_(something) {
|
|
|
52
61
|
return Fail(e);
|
|
53
62
|
}
|
|
54
63
|
}
|
|
64
|
+
const map = (result,
|
|
65
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
66
|
+
mapFn) => {
|
|
67
|
+
const [error, resultValue] = result;
|
|
68
|
+
if (error) {
|
|
69
|
+
return Fail(error);
|
|
70
|
+
}
|
|
71
|
+
return catch_(() => mapFn(resultValue));
|
|
72
|
+
};
|
|
55
73
|
/**
|
|
56
74
|
* Singleton object with small methods for creating, mapping or handling
|
|
57
75
|
* `ResultTupleObj` instances.
|
|
@@ -80,12 +98,13 @@ export const Result = {
|
|
|
80
98
|
*
|
|
81
99
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulmap
|
|
82
100
|
*/
|
|
101
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
83
102
|
map: (result, mapFn) => {
|
|
84
103
|
const [error, resultValue] = result;
|
|
85
104
|
if (error) {
|
|
86
105
|
return Fail(error);
|
|
87
106
|
}
|
|
88
|
-
return
|
|
107
|
+
return catch_(() => mapFn(resultValue));
|
|
89
108
|
},
|
|
90
109
|
/**
|
|
91
110
|
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
@@ -93,6 +112,7 @@ export const Result = {
|
|
|
93
112
|
*
|
|
94
113
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resulthrow
|
|
95
114
|
*/
|
|
115
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
96
116
|
throw: (result) => {
|
|
97
117
|
if (result[0]) {
|
|
98
118
|
throw result[0];
|
|
@@ -1,83 +1,57 @@
|
|
|
1
|
-
export declare const _PatchedCollator: {
|
|
2
|
-
(locales?: string | string[] | undefined, options?: Intl.CollatorOptions | undefined): Intl.Collator;
|
|
3
|
-
new (locales?: string | string[] | undefined, options?: Intl.CollatorOptions | undefined): Intl.Collator;
|
|
4
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.CollatorOptions | undefined): string[];
|
|
5
|
-
} & {
|
|
1
|
+
export declare const _PatchedCollator: typeof Intl.Collator & {
|
|
6
2
|
$original: typeof Intl.Collator;
|
|
7
3
|
};
|
|
8
4
|
export declare const _patchedStringLocaleCompare: {
|
|
9
5
|
(this: string, that: string, locales?: string | Array<string>, options?: Intl.CollatorOptions): number;
|
|
10
6
|
$original: {
|
|
11
7
|
(that: string): number;
|
|
12
|
-
(that: string, locales?: string | string[]
|
|
8
|
+
(that: string, locales?: string | string[], options?: Intl.CollatorOptions): number;
|
|
9
|
+
(that: string, locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): number;
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
|
-
export declare const _PatchedNumberFormat: {
|
|
16
|
-
(locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat;
|
|
17
|
-
new (locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat;
|
|
18
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions | undefined): string[];
|
|
19
|
-
readonly prototype: Intl.NumberFormat;
|
|
20
|
-
} & {
|
|
12
|
+
export declare const _PatchedNumberFormat: typeof Intl.NumberFormat & {
|
|
21
13
|
$original: typeof Intl.NumberFormat;
|
|
22
14
|
};
|
|
23
15
|
export declare const _patchedNumberToLocaleString: {
|
|
24
16
|
(this: number, locales?: string | Array<string>, options?: Intl.NumberFormatOptions): string;
|
|
25
17
|
$original: {
|
|
26
|
-
(locales?: string | string[]
|
|
27
|
-
(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions
|
|
18
|
+
(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
19
|
+
(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
|
28
20
|
};
|
|
29
21
|
};
|
|
30
|
-
export declare const _PatchedDateTimeFormat: {
|
|
31
|
-
(locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat;
|
|
32
|
-
new (locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat;
|
|
33
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions | undefined): string[];
|
|
34
|
-
readonly prototype: Intl.DateTimeFormat;
|
|
35
|
-
} & {
|
|
22
|
+
export declare const _PatchedDateTimeFormat: typeof Intl.DateTimeFormat & {
|
|
36
23
|
$original: typeof Intl.DateTimeFormat;
|
|
37
24
|
};
|
|
38
25
|
export declare const _patchedDateToLocaleString: {
|
|
39
26
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
40
27
|
$original: {
|
|
41
28
|
(): string;
|
|
42
|
-
(locales?: string | string[]
|
|
43
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
29
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
30
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
44
31
|
};
|
|
45
32
|
};
|
|
46
33
|
export declare const _patchedDateToLocaleDateString: {
|
|
47
34
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
48
35
|
$original: {
|
|
49
36
|
(): string;
|
|
50
|
-
(locales?: string | string[]
|
|
51
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
37
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
38
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
52
39
|
};
|
|
53
40
|
};
|
|
54
41
|
export declare const _patchedDateToLocaleTimeString: {
|
|
55
42
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
56
43
|
$original: {
|
|
57
44
|
(): string;
|
|
58
|
-
(locales?: string | string[]
|
|
59
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
45
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
46
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
60
47
|
};
|
|
61
48
|
};
|
|
62
|
-
export declare const _PatchedPluralRules: {
|
|
63
|
-
(locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules;
|
|
64
|
-
new (locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules;
|
|
65
|
-
supportedLocalesOf(locales: string | string[], options?: {
|
|
66
|
-
localeMatcher?: "best fit" | "lookup" | undefined;
|
|
67
|
-
} | undefined): string[];
|
|
68
|
-
} & {
|
|
49
|
+
export declare const _PatchedPluralRules: typeof Intl.PluralRules & {
|
|
69
50
|
$original: typeof Intl.PluralRules;
|
|
70
51
|
};
|
|
71
|
-
export declare const _PatchedListFormat: {
|
|
72
|
-
new (locales?: string | string[] | undefined, options?: Intl.ListFormatOptions | undefined): Intl.ListFormat;
|
|
73
|
-
prototype: Intl.ListFormat;
|
|
74
|
-
supportedLocalesOf(locales: string | string[], options?: Pick<Intl.ListFormatOptions, "localeMatcher"> | undefined): string[];
|
|
75
|
-
} & {
|
|
52
|
+
export declare const _PatchedListFormat: typeof Intl.ListFormat & {
|
|
76
53
|
$original: typeof Intl.ListFormat;
|
|
77
54
|
};
|
|
78
|
-
export declare const _PatchedRelativeTimeFormat: {
|
|
79
|
-
new (locales?: string | string[] | undefined, options?: Intl.RelativeTimeFormatOptions | undefined): Intl.RelativeTimeFormat;
|
|
80
|
-
supportedLocalesOf(locales?: string | string[] | undefined, options?: Intl.RelativeTimeFormatOptions | undefined): string[];
|
|
81
|
-
} & {
|
|
55
|
+
export declare const _PatchedRelativeTimeFormat: typeof Intl.RelativeTimeFormat & {
|
|
82
56
|
$original: typeof Intl.RelativeTimeFormat;
|
|
83
57
|
};
|
|
@@ -210,9 +210,9 @@ const partMappers = {
|
|
|
210
210
|
const reformatDateTimeParts = function (parent, parts) {
|
|
211
211
|
const options = parent.resolvedOptions();
|
|
212
212
|
parts.forEach((part, idx) => {
|
|
213
|
-
var
|
|
213
|
+
var _d;
|
|
214
214
|
const mapper = partMappers[part.type];
|
|
215
|
-
const newValue = mapper && mapper(part.value, (
|
|
215
|
+
const newValue = mapper && mapper(part.value, (_d = parts[idx - 1]) === null || _d === void 0 ? void 0 : _d.type, options);
|
|
216
216
|
if (newValue != null) {
|
|
217
217
|
part.value = newValue;
|
|
218
218
|
}
|
|
@@ -436,7 +436,7 @@ if (_RelativeTimeFormat) {
|
|
|
436
436
|
'i går': 'í gær',
|
|
437
437
|
'i dag': 'í dag',
|
|
438
438
|
'i morgen': 'á morgun',
|
|
439
|
-
'i overmorgen': 'eftir tvo daga',
|
|
439
|
+
'i overmorgen': 'eftir tvo daga', // 'á hinn daginn',
|
|
440
440
|
'denne time': 'þessa stundina',
|
|
441
441
|
'dette minut': 'á þessari mínútu',
|
|
442
442
|
};
|
package/esm/http.d.ts
CHANGED
package/esm/http.js
CHANGED
|
@@ -138,6 +138,7 @@ const unitToSeconds = {
|
|
|
138
138
|
*
|
|
139
139
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
140
140
|
*/
|
|
141
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
141
142
|
export const toSec = (ttl) => {
|
|
142
143
|
if (typeof ttl === 'string') {
|
|
143
144
|
const value = parseFloat(ttl);
|
|
@@ -152,7 +153,9 @@ export const toSec = (ttl) => {
|
|
|
152
153
|
*
|
|
153
154
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#toms-duration-helper
|
|
154
155
|
*/
|
|
156
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
155
157
|
export const toMs = (ttl) => toSec(ttl) * 1000;
|
|
158
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
156
159
|
const toRespnseStubHeaders = (response) => {
|
|
157
160
|
if (response instanceof Map) {
|
|
158
161
|
return response;
|
|
@@ -177,6 +180,7 @@ const stabilities = {
|
|
|
177
180
|
immutable: ', immutable',
|
|
178
181
|
normal: '',
|
|
179
182
|
};
|
|
183
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
180
184
|
const setCC = (response, cc) => {
|
|
181
185
|
const devModeHeader = 'X-Cache-Control';
|
|
182
186
|
const headers = toRespnseStubHeaders(response);
|
|
@@ -197,7 +201,7 @@ const setCC = (response, cc) => {
|
|
|
197
201
|
*
|
|
198
202
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrol-helper
|
|
199
203
|
*/
|
|
200
|
-
// eslint-disable-next-line complexity
|
|
204
|
+
/*#__NO_SIDE_EFFECTS__*/ // eslint-disable-next-line complexity
|
|
201
205
|
export const cacheControl = (response, ttlCfg, eTag) => {
|
|
202
206
|
response = 'res' in response ? response.res : response;
|
|
203
207
|
const opts = typeof ttlCfg === 'number' || typeof ttlCfg === 'string'
|
|
@@ -240,6 +244,7 @@ export const cacheControl = (response, ttlCfg, eTag) => {
|
|
|
240
244
|
* Accepts the same arguments as `cacheControl()`.
|
|
241
245
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrolheaders-helper
|
|
242
246
|
*/
|
|
247
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
243
248
|
export const cacheControlHeaders = (ttlCfg, eTag) => {
|
|
244
249
|
const headers = new Map();
|
|
245
250
|
cacheControl(headers, ttlCfg, eTag);
|
package/esm/next/http.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import React, { FunctionComponent } from 'react';
|
|
3
2
|
import type { Cleanup } from '@reykjavik/hanna-utils';
|
|
4
3
|
import type { AppType } from 'next/app.js';
|
|
@@ -28,10 +27,10 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
28
27
|
*
|
|
29
28
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
30
29
|
*/
|
|
31
|
-
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage:
|
|
30
|
+
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: FunctionComponent<EP>) => {
|
|
32
31
|
<P extends {
|
|
33
32
|
[key: string]: unknown;
|
|
34
|
-
__error?:
|
|
33
|
+
__error?: never;
|
|
35
34
|
}>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils.js").AppPropsType<any, P | ({
|
|
36
35
|
__error: ErrorProps;
|
|
37
36
|
} & Omit<ErrorProps & EP, keyof ErrorProps>)>> & {
|
package/esm/next/http.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from '../http.js';
|
|
|
11
11
|
*
|
|
12
12
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#showerrorpage-helper
|
|
13
13
|
*/
|
|
14
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
14
15
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
15
16
|
error =
|
|
16
17
|
typeof error === 'number'
|
|
@@ -35,6 +36,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
35
36
|
*
|
|
36
37
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
37
38
|
*/
|
|
39
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
38
40
|
export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
39
41
|
// the HOC
|
|
40
42
|
const withErrorHandling = (App) => {
|
|
@@ -64,6 +66,7 @@ export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
|
64
66
|
*
|
|
65
67
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
66
68
|
*/
|
|
69
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
67
70
|
export const notModified304 = (response) => {
|
|
68
71
|
response = 'res' in response ? response.res : response;
|
|
69
72
|
response.statusCode = HTTP_304_NotModified;
|
package/esm/react-router/http.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
7
8
|
export const isClientFetch = (request) =>
|
|
8
9
|
// For info about this detection method:
|
|
9
10
|
// - https://github.com/remix-run/remix/discussions/5583
|
|
@@ -1,83 +1,57 @@
|
|
|
1
|
-
export declare const _PatchedCollator: {
|
|
2
|
-
(locales?: string | string[] | undefined, options?: Intl.CollatorOptions | undefined): Intl.Collator;
|
|
3
|
-
new (locales?: string | string[] | undefined, options?: Intl.CollatorOptions | undefined): Intl.Collator;
|
|
4
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.CollatorOptions | undefined): string[];
|
|
5
|
-
} & {
|
|
1
|
+
export declare const _PatchedCollator: typeof Intl.Collator & {
|
|
6
2
|
$original: typeof Intl.Collator;
|
|
7
3
|
};
|
|
8
4
|
export declare const _patchedStringLocaleCompare: {
|
|
9
5
|
(this: string, that: string, locales?: string | Array<string>, options?: Intl.CollatorOptions): number;
|
|
10
6
|
$original: {
|
|
11
7
|
(that: string): number;
|
|
12
|
-
(that: string, locales?: string | string[]
|
|
8
|
+
(that: string, locales?: string | string[], options?: Intl.CollatorOptions): number;
|
|
9
|
+
(that: string, locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): number;
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
|
-
export declare const _PatchedNumberFormat: {
|
|
16
|
-
(locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat;
|
|
17
|
-
new (locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat;
|
|
18
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions | undefined): string[];
|
|
19
|
-
readonly prototype: Intl.NumberFormat;
|
|
20
|
-
} & {
|
|
12
|
+
export declare const _PatchedNumberFormat: typeof Intl.NumberFormat & {
|
|
21
13
|
$original: typeof Intl.NumberFormat;
|
|
22
14
|
};
|
|
23
15
|
export declare const _patchedNumberToLocaleString: {
|
|
24
16
|
(this: number, locales?: string | Array<string>, options?: Intl.NumberFormatOptions): string;
|
|
25
17
|
$original: {
|
|
26
|
-
(locales?: string | string[]
|
|
27
|
-
(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions
|
|
18
|
+
(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
19
|
+
(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
|
28
20
|
};
|
|
29
21
|
};
|
|
30
|
-
export declare const _PatchedDateTimeFormat: {
|
|
31
|
-
(locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat;
|
|
32
|
-
new (locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat;
|
|
33
|
-
supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions | undefined): string[];
|
|
34
|
-
readonly prototype: Intl.DateTimeFormat;
|
|
35
|
-
} & {
|
|
22
|
+
export declare const _PatchedDateTimeFormat: typeof Intl.DateTimeFormat & {
|
|
36
23
|
$original: typeof Intl.DateTimeFormat;
|
|
37
24
|
};
|
|
38
25
|
export declare const _patchedDateToLocaleString: {
|
|
39
26
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
40
27
|
$original: {
|
|
41
28
|
(): string;
|
|
42
|
-
(locales?: string | string[]
|
|
43
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
29
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
30
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
44
31
|
};
|
|
45
32
|
};
|
|
46
33
|
export declare const _patchedDateToLocaleDateString: {
|
|
47
34
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
48
35
|
$original: {
|
|
49
36
|
(): string;
|
|
50
|
-
(locales?: string | string[]
|
|
51
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
37
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
38
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
52
39
|
};
|
|
53
40
|
};
|
|
54
41
|
export declare const _patchedDateToLocaleTimeString: {
|
|
55
42
|
(this: Date, locales?: string | Array<string>, options?: Intl.DateTimeFormatOptions): string;
|
|
56
43
|
$original: {
|
|
57
44
|
(): string;
|
|
58
|
-
(locales?: string | string[]
|
|
59
|
-
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions
|
|
45
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
46
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
60
47
|
};
|
|
61
48
|
};
|
|
62
|
-
export declare const _PatchedPluralRules: {
|
|
63
|
-
(locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules;
|
|
64
|
-
new (locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules;
|
|
65
|
-
supportedLocalesOf(locales: string | string[], options?: {
|
|
66
|
-
localeMatcher?: "best fit" | "lookup" | undefined;
|
|
67
|
-
} | undefined): string[];
|
|
68
|
-
} & {
|
|
49
|
+
export declare const _PatchedPluralRules: typeof Intl.PluralRules & {
|
|
69
50
|
$original: typeof Intl.PluralRules;
|
|
70
51
|
};
|
|
71
|
-
export declare const _PatchedListFormat: {
|
|
72
|
-
new (locales?: string | string[] | undefined, options?: Intl.ListFormatOptions | undefined): Intl.ListFormat;
|
|
73
|
-
prototype: Intl.ListFormat;
|
|
74
|
-
supportedLocalesOf(locales: string | string[], options?: Pick<Intl.ListFormatOptions, "localeMatcher"> | undefined): string[];
|
|
75
|
-
} & {
|
|
52
|
+
export declare const _PatchedListFormat: typeof Intl.ListFormat & {
|
|
76
53
|
$original: typeof Intl.ListFormat;
|
|
77
54
|
};
|
|
78
|
-
export declare const _PatchedRelativeTimeFormat: {
|
|
79
|
-
new (locales?: string | string[] | undefined, options?: Intl.RelativeTimeFormatOptions | undefined): Intl.RelativeTimeFormat;
|
|
80
|
-
supportedLocalesOf(locales?: string | string[] | undefined, options?: Intl.RelativeTimeFormatOptions | undefined): string[];
|
|
81
|
-
} & {
|
|
55
|
+
export declare const _PatchedRelativeTimeFormat: typeof Intl.RelativeTimeFormat & {
|
|
82
56
|
$original: typeof Intl.RelativeTimeFormat;
|
|
83
57
|
};
|
|
@@ -215,9 +215,9 @@ const partMappers = {
|
|
|
215
215
|
const reformatDateTimeParts = function (parent, parts) {
|
|
216
216
|
const options = parent.resolvedOptions();
|
|
217
217
|
parts.forEach((part, idx) => {
|
|
218
|
-
var
|
|
218
|
+
var _d;
|
|
219
219
|
const mapper = partMappers[part.type];
|
|
220
|
-
const newValue = mapper && mapper(part.value, (
|
|
220
|
+
const newValue = mapper && mapper(part.value, (_d = parts[idx - 1]) === null || _d === void 0 ? void 0 : _d.type, options);
|
|
221
221
|
if (newValue != null) {
|
|
222
222
|
part.value = newValue;
|
|
223
223
|
}
|
|
@@ -444,7 +444,7 @@ if (_RelativeTimeFormat) {
|
|
|
444
444
|
'i går': 'í gær',
|
|
445
445
|
'i dag': 'í dag',
|
|
446
446
|
'i morgen': 'á morgun',
|
|
447
|
-
'i overmorgen': 'eftir tvo daga',
|
|
447
|
+
'i overmorgen': 'eftir tvo daga', // 'á hinn daginn',
|
|
448
448
|
'denne time': 'þessa stundina',
|
|
449
449
|
'dette minut': 'á þessari mínútu',
|
|
450
450
|
};
|
package/http.d.ts
CHANGED
package/http.js
CHANGED
|
@@ -142,6 +142,7 @@ const unitToSeconds = {
|
|
|
142
142
|
*
|
|
143
143
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
144
144
|
*/
|
|
145
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
145
146
|
const toSec = (ttl) => {
|
|
146
147
|
if (typeof ttl === 'string') {
|
|
147
148
|
const value = parseFloat(ttl);
|
|
@@ -157,8 +158,10 @@ exports.toSec = toSec;
|
|
|
157
158
|
*
|
|
158
159
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#toms-duration-helper
|
|
159
160
|
*/
|
|
161
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
160
162
|
const toMs = (ttl) => (0, exports.toSec)(ttl) * 1000;
|
|
161
163
|
exports.toMs = toMs;
|
|
164
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
162
165
|
const toRespnseStubHeaders = (response) => {
|
|
163
166
|
if (response instanceof Map) {
|
|
164
167
|
return response;
|
|
@@ -183,6 +186,7 @@ const stabilities = {
|
|
|
183
186
|
immutable: ', immutable',
|
|
184
187
|
normal: '',
|
|
185
188
|
};
|
|
189
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
186
190
|
const setCC = (response, cc) => {
|
|
187
191
|
const devModeHeader = 'X-Cache-Control';
|
|
188
192
|
const headers = toRespnseStubHeaders(response);
|
|
@@ -203,7 +207,7 @@ const setCC = (response, cc) => {
|
|
|
203
207
|
*
|
|
204
208
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrol-helper
|
|
205
209
|
*/
|
|
206
|
-
// eslint-disable-next-line complexity
|
|
210
|
+
/*#__NO_SIDE_EFFECTS__*/ // eslint-disable-next-line complexity
|
|
207
211
|
const cacheControl = (response, ttlCfg, eTag) => {
|
|
208
212
|
response = 'res' in response ? response.res : response;
|
|
209
213
|
const opts = typeof ttlCfg === 'number' || typeof ttlCfg === 'string'
|
|
@@ -247,6 +251,7 @@ exports.cacheControl = cacheControl;
|
|
|
247
251
|
* Accepts the same arguments as `cacheControl()`.
|
|
248
252
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrolheaders-helper
|
|
249
253
|
*/
|
|
254
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
250
255
|
const cacheControlHeaders = (ttlCfg, eTag) => {
|
|
251
256
|
const headers = new Map();
|
|
252
257
|
(0, exports.cacheControl)(headers, ttlCfg, eTag);
|
package/next/http.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import React, { FunctionComponent } from 'react';
|
|
3
2
|
import type { Cleanup } from '@reykjavik/hanna-utils';
|
|
4
3
|
import type { AppType } from 'next/app.js';
|
|
@@ -28,10 +27,10 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
28
27
|
*
|
|
29
28
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
30
29
|
*/
|
|
31
|
-
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage:
|
|
30
|
+
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: FunctionComponent<EP>) => {
|
|
32
31
|
<P extends {
|
|
33
32
|
[key: string]: unknown;
|
|
34
|
-
__error?:
|
|
33
|
+
__error?: never;
|
|
35
34
|
}>(App: AppType<P>): React.FunctionComponent<import("next/dist/shared/lib/utils.js").AppPropsType<any, P | ({
|
|
36
35
|
__error: ErrorProps;
|
|
37
36
|
} & Omit<ErrorProps & EP, keyof ErrorProps>)>> & {
|
package/next/http.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("../http.js"), exports);
|
|
|
31
31
|
*
|
|
32
32
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#showerrorpage-helper
|
|
33
33
|
*/
|
|
34
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
34
35
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
35
36
|
error =
|
|
36
37
|
typeof error === 'number'
|
|
@@ -55,6 +56,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
55
56
|
*
|
|
56
57
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
57
58
|
*/
|
|
59
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
58
60
|
const makeErrorizeAppHOC = (ErrorPage) => {
|
|
59
61
|
// the HOC
|
|
60
62
|
const withErrorHandling = (App) => {
|
|
@@ -85,6 +87,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
|
|
|
85
87
|
*
|
|
86
88
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
87
89
|
*/
|
|
90
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
88
91
|
const notModified304 = (response) => {
|
|
89
92
|
response = 'res' in response ? response.res : response;
|
|
90
93
|
response.statusCode = http_js_1.HTTP_304_NotModified;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reykjavik/webtools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "ssh://git@github.com:reykjavikcity/webtools.git",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@reykjavik/hanna-utils": "^0.2.
|
|
14
|
+
"@reykjavik/hanna-utils": "^0.2.20"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@vanilla-extract/css": "^1.14.1",
|
package/react-router/Wait.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.Wait = void 0;
|
|
27
37
|
const react_1 = __importStar(require("react"));
|
package/react-router/http.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.isClientFetch = void 0;
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#isclientfetch
|
|
9
9
|
*/
|
|
10
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
10
11
|
const isClientFetch = (request) =>
|
|
11
12
|
// For info about this detection method:
|
|
12
13
|
// - https://github.com/remix-run/remix/discussions/5583
|
package/vanillaExtract.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.vanillaProps = exports.vanillaGlobal = void 0;
|
|
4
|
+
exports.vanillaClass = vanillaClass;
|
|
4
5
|
const css_1 = require("@vanilla-extract/css");
|
|
5
6
|
/**
|
|
6
7
|
* Adds free-form CSS as a globalStyle
|
|
@@ -30,4 +31,3 @@ function vanillaClass(cssOrDebugId, css) {
|
|
|
30
31
|
: css.replace(/&&/g, `.${className}`));
|
|
31
32
|
return className;
|
|
32
33
|
}
|
|
33
|
-
exports.vanillaClass = vanillaClass;
|