@reykjavik/webtools 0.2.6 → 0.2.7
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 +8 -0
- package/README.md +7 -4
- package/errorhandling.d.ts +11 -3
- package/errorhandling.js +2 -2
- package/esm/errorhandling.d.ts +11 -3
- package/esm/errorhandling.js +2 -2
- package/esm/fixIcelandicLocale.js +4 -0
- package/esm/http.d.ts +1 -0
- package/esm/http.js +1 -1
- package/fixIcelandicLocale.js +4 -0
- package/http.d.ts +1 -0
- package/http.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.2.7
|
|
8
|
+
|
|
9
|
+
_2025-09-01_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/fixIcelandicLocale`:
|
|
12
|
+
- fix: Check for support of each Intl class separately
|
|
13
|
+
- docs: Improve JSDocs and README for `asError()` and `ErrorFromPayload`
|
|
14
|
+
|
|
7
15
|
## 0.2.6
|
|
8
16
|
|
|
9
17
|
_2025-06-20_
|
package/README.md
CHANGED
|
@@ -386,7 +386,8 @@ Guarantees that a caught (`catch (e)`) value of `unknown` type, is indeed an
|
|
|
386
386
|
|
|
387
387
|
If the input is an `Error` instance, it is returned as-is. If the input is
|
|
388
388
|
something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
389
|
-
original value is stored in as a `payload` property
|
|
389
|
+
original value is stored in as a `payload` property, and it's `.toString()` is
|
|
390
|
+
used for the `message` property.
|
|
390
391
|
|
|
391
392
|
```ts
|
|
392
393
|
import { asError, type ErrorFromPayload } from '@reykjavik/webtools/errorhandling';
|
|
@@ -395,21 +396,23 @@ const theError = new Error('Something went wrong');
|
|
|
395
396
|
try {
|
|
396
397
|
throw theError;
|
|
397
398
|
} catch (err) {
|
|
399
|
+
// theError is an instance of Error so it's returned as-is
|
|
398
400
|
const error = asError(theError);
|
|
399
401
|
console.error(error === theError); // true
|
|
400
|
-
console.error('
|
|
402
|
+
console.error('payload' in error); // false
|
|
401
403
|
}
|
|
402
404
|
|
|
403
|
-
const someObject = ['Something went wrong'];
|
|
405
|
+
const someObject = ['Oops', 'Something went wrong'];
|
|
404
406
|
try {
|
|
405
407
|
throw someObject;
|
|
406
408
|
} catch (err) {
|
|
409
|
+
// the thrown someObject is not an Error so an `ErrorFromPayload` is returned
|
|
407
410
|
const error = asError(someObject);
|
|
408
411
|
console.error(error === someObject); // false
|
|
409
|
-
console.error(error.message === someObject.join(',')); // false
|
|
410
412
|
console.error(error instanceOf ErrorFromPayload); // true
|
|
411
413
|
|
|
412
414
|
console.error(error.payload === someObject); // true
|
|
415
|
+
console.error(error.message === someObject.join(',')); // true
|
|
413
416
|
}
|
|
414
417
|
```
|
|
415
418
|
|
package/errorhandling.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error subclass for thrown values that got
|
|
3
|
-
* Error, with the thrown value as the `payload` property.
|
|
2
|
+
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
|
+
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
export declare class ErrorFromPayload extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* This payload property is only set if the original `throw` value was NOT
|
|
10
|
+
* `instanceof Error`.
|
|
11
|
+
*
|
|
12
|
+
* In such cases it contains the thrown value as is, and the `message`
|
|
13
|
+
* property of this `ErrorFromPayload` instance is set to the `.toString()`
|
|
14
|
+
* representation of the payload.
|
|
15
|
+
*/
|
|
8
16
|
payload?: unknown;
|
|
9
17
|
constructor(payload: unknown);
|
|
10
18
|
name: string;
|
|
@@ -50,7 +58,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
|
|
|
50
58
|
* `[error, results]` tuple with the `result` and `error` also attached as
|
|
51
59
|
* named properties.
|
|
52
60
|
*
|
|
53
|
-
* Works on both promises and
|
|
61
|
+
* Works on both promises and (synchronous) callback functions.
|
|
54
62
|
*
|
|
55
63
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultcatch
|
|
56
64
|
*/
|
package/errorhandling.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Error subclass for thrown values that got
|
|
6
|
-
* Error, with the thrown value as the `payload` property.
|
|
5
|
+
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
6
|
+
* Error, with the original thrown value as the `payload` property.
|
|
7
7
|
*
|
|
8
8
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
9
9
|
*/
|
package/esm/errorhandling.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error subclass for thrown values that got
|
|
3
|
-
* Error, with the thrown value as the `payload` property.
|
|
2
|
+
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
|
+
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
6
6
|
*/
|
|
7
7
|
export declare class ErrorFromPayload extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* This payload property is only set if the original `throw` value was NOT
|
|
10
|
+
* `instanceof Error`.
|
|
11
|
+
*
|
|
12
|
+
* In such cases it contains the thrown value as is, and the `message`
|
|
13
|
+
* property of this `ErrorFromPayload` instance is set to the `.toString()`
|
|
14
|
+
* representation of the payload.
|
|
15
|
+
*/
|
|
8
16
|
payload?: unknown;
|
|
9
17
|
constructor(payload: unknown);
|
|
10
18
|
name: string;
|
|
@@ -50,7 +58,7 @@ export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | Fail
|
|
|
50
58
|
* `[error, results]` tuple with the `result` and `error` also attached as
|
|
51
59
|
* named properties.
|
|
52
60
|
*
|
|
53
|
-
* Works on both promises and
|
|
61
|
+
* Works on both promises and (synchronous) callback functions.
|
|
54
62
|
*
|
|
55
63
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#resultcatch
|
|
56
64
|
*/
|
package/esm/errorhandling.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error subclass for thrown values that got
|
|
3
|
-
* Error, with the thrown value as the `payload` property.
|
|
2
|
+
* Error subclass for thrown NON-Error values that got turned into an actual
|
|
3
|
+
* Error, with the original thrown value as the `payload` property.
|
|
4
4
|
*
|
|
5
5
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#aserror
|
|
6
6
|
*/
|
|
@@ -7,8 +7,12 @@ import { _PatchedCollator, _PatchedDateTimeFormat, _patchedDateToLocaleDateStrin
|
|
|
7
7
|
if (!Intl.Collator.supportedLocalesOf(['is']).length) {
|
|
8
8
|
Intl.Collator = _PatchedCollator;
|
|
9
9
|
String.prototype.localeCompare = _patchedStringLocaleCompare;
|
|
10
|
+
}
|
|
11
|
+
if (!Intl.NumberFormat.supportedLocalesOf(['is']).length) {
|
|
10
12
|
Intl.NumberFormat = _PatchedNumberFormat;
|
|
11
13
|
Number.prototype.toLocaleString = _patchedNumberToLocaleString;
|
|
14
|
+
}
|
|
15
|
+
if (!Intl.DateTimeFormat.supportedLocalesOf(['is']).length) {
|
|
12
16
|
Intl.DateTimeFormat = _PatchedDateTimeFormat;
|
|
13
17
|
Date.prototype.toLocaleString = _patchedDateToLocaleString;
|
|
14
18
|
Date.prototype.toLocaleDateString = _patchedDateToLocaleDateString;
|
package/esm/http.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const HTTP_103_EarlyHints = 103;
|
|
|
11
11
|
export declare const HTTP_200_OK = 200;
|
|
12
12
|
/** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
|
|
13
13
|
export declare const HTTP_201_Created = 201;
|
|
14
|
+
/** The request has been received but not yet acted upon. Another process or server handles the request. */
|
|
14
15
|
export declare const HTTP_202_Accepted = 202;
|
|
15
16
|
/** The returned metadata is not necessarily complete. */
|
|
16
17
|
export declare const HTTP_203_NonAuthoritativeInformation = 203;
|
package/esm/http.js
CHANGED
|
@@ -12,7 +12,7 @@ export const HTTP_103_EarlyHints = 103;
|
|
|
12
12
|
export const HTTP_200_OK = 200;
|
|
13
13
|
/** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
|
|
14
14
|
export const HTTP_201_Created = 201;
|
|
15
|
-
|
|
15
|
+
/** The request has been received but not yet acted upon. Another process or server handles the request. */
|
|
16
16
|
export const HTTP_202_Accepted = 202;
|
|
17
17
|
/** The returned metadata is not necessarily complete. */
|
|
18
18
|
export const HTTP_203_NonAuthoritativeInformation = 203;
|
package/fixIcelandicLocale.js
CHANGED
|
@@ -9,8 +9,12 @@ const fixIcelandicLocale_privates_js_1 = require("./fixIcelandicLocale.privates.
|
|
|
9
9
|
if (!Intl.Collator.supportedLocalesOf(['is']).length) {
|
|
10
10
|
Intl.Collator = fixIcelandicLocale_privates_js_1._PatchedCollator;
|
|
11
11
|
String.prototype.localeCompare = fixIcelandicLocale_privates_js_1._patchedStringLocaleCompare;
|
|
12
|
+
}
|
|
13
|
+
if (!Intl.NumberFormat.supportedLocalesOf(['is']).length) {
|
|
12
14
|
Intl.NumberFormat = fixIcelandicLocale_privates_js_1._PatchedNumberFormat;
|
|
13
15
|
Number.prototype.toLocaleString = fixIcelandicLocale_privates_js_1._patchedNumberToLocaleString;
|
|
16
|
+
}
|
|
17
|
+
if (!Intl.DateTimeFormat.supportedLocalesOf(['is']).length) {
|
|
14
18
|
Intl.DateTimeFormat = fixIcelandicLocale_privates_js_1._PatchedDateTimeFormat;
|
|
15
19
|
Date.prototype.toLocaleString = fixIcelandicLocale_privates_js_1._patchedDateToLocaleString;
|
|
16
20
|
Date.prototype.toLocaleDateString = fixIcelandicLocale_privates_js_1._patchedDateToLocaleDateString;
|
package/http.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const HTTP_103_EarlyHints = 103;
|
|
|
11
11
|
export declare const HTTP_200_OK = 200;
|
|
12
12
|
/** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
|
|
13
13
|
export declare const HTTP_201_Created = 201;
|
|
14
|
+
/** The request has been received but not yet acted upon. Another process or server handles the request. */
|
|
14
15
|
export declare const HTTP_202_Accepted = 202;
|
|
15
16
|
/** The returned metadata is not necessarily complete. */
|
|
16
17
|
export declare const HTTP_203_NonAuthoritativeInformation = 203;
|
package/http.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.HTTP_103_EarlyHints = 103;
|
|
|
16
16
|
exports.HTTP_200_OK = 200;
|
|
17
17
|
/** The request succeeded, and a new resource was created as a result. This is typically the response sent after POST or PUT requests. */
|
|
18
18
|
exports.HTTP_201_Created = 201;
|
|
19
|
-
|
|
19
|
+
/** The request has been received but not yet acted upon. Another process or server handles the request. */
|
|
20
20
|
exports.HTTP_202_Accepted = 202;
|
|
21
21
|
/** The returned metadata is not necessarily complete. */
|
|
22
22
|
exports.HTTP_203_NonAuthoritativeInformation = 203;
|
package/package.json
CHANGED