@theholocron/misc-utils 1.8.2 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +12 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@theholocron/misc-utils`
|
|
2
2
|
|
|
3
|
-
Miscellaneous
|
|
3
|
+
Miscellaneous utilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,6 +10,23 @@ pnpm add @theholocron/misc-utils
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
### `errorMessage(err)`
|
|
14
|
+
|
|
15
|
+
Stringifies a caught value for display — `err.message` for a real
|
|
16
|
+
`Error`, `String(err)` for anything else. `catch` blocks only ever get
|
|
17
|
+
`unknown` in TypeScript; this is the one line nearly every one of them
|
|
18
|
+
needs.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
doSomething();
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(errorMessage(err));
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
13
30
|
### Konami code detector
|
|
14
31
|
|
|
15
32
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
type TKonamiCode = "ArrowDown" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "KeyA" | "KeyB";
|
|
3
3
|
declare function is(event: KeyboardEvent): boolean;
|
|
4
4
|
//#endregion
|
|
5
|
+
//#region src/error-message.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Stringifies a caught value for display — `err.message` for a real
|
|
8
|
+
* `Error`, `String(err)` for anything else (a thrown string, a plugin's
|
|
9
|
+
* custom error-like object, …). `catch` blocks only ever get `unknown`
|
|
10
|
+
* in TypeScript, so this is the one line nearly every one of them needs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function errorMessage(err: unknown): string;
|
|
13
|
+
//#endregion
|
|
5
14
|
//#region src/index.d.ts
|
|
6
15
|
export declare const konami: {
|
|
7
16
|
CODE: TKonamiCode[];
|
package/dist/index.mjs
CHANGED
|
@@ -23,10 +23,21 @@ function is(event) {
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
+
//#region src/error-message.ts
|
|
27
|
+
/**
|
|
28
|
+
* Stringifies a caught value for display — `err.message` for a real
|
|
29
|
+
* `Error`, `String(err)` for anything else (a thrown string, a plugin's
|
|
30
|
+
* custom error-like object, …). `catch` blocks only ever get `unknown`
|
|
31
|
+
* in TypeScript, so this is the one line nearly every one of them needs.
|
|
32
|
+
*/
|
|
33
|
+
function errorMessage(err) {
|
|
34
|
+
return err instanceof Error ? err.message : String(err);
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
26
37
|
//#region src/index.ts
|
|
27
38
|
const konami = {
|
|
28
39
|
CODE,
|
|
29
40
|
is
|
|
30
41
|
};
|
|
31
42
|
//#endregion
|
|
32
|
-
export { konami };
|
|
43
|
+
export { errorMessage, konami };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/misc-utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"description": "Miscellaneous utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"misc",
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"types": "./dist/index.d.
|
|
24
|
-
"import": "./dist/index.
|
|
25
|
-
"default": "./dist/index.
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"default": "./dist/index.mjs"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@theholocron/cli": "5.0.0-alpha.3",
|
|
32
33
|
"@theholocron/tsdown-config": "^8.2.0",
|
|
33
34
|
"@theholocron/vitest-config": "^8.2.0",
|
|
34
35
|
"@tsconfig/node-lts": "^24.0.1",
|
|
@@ -46,10 +47,10 @@
|
|
|
46
47
|
"releases": "https://github.com/theholocron/utils/releases",
|
|
47
48
|
"wiki": "https://github.com/theholocron/utils/wiki",
|
|
48
49
|
"scripts": {
|
|
49
|
-
"build": "tsdown",
|
|
50
|
-
"
|
|
51
|
-
"test": "vitest
|
|
52
|
-
"
|
|
53
|
-
"
|
|
50
|
+
"delivery.build": "tsdown",
|
|
51
|
+
"sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"verification.typeSafety": "holocron run verification.typeSafety --",
|
|
54
|
+
"verification.unitTests": "holocron run verification.unitTests --"
|
|
54
55
|
}
|
|
55
56
|
}
|