@douglasneuroinformatics/libjs 2.1.0 → 2.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.
- package/dist/exception.d.ts +5 -2
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +32 -0
- package/dist/string.d.ts +1 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +3 -0
- package/package.json +5 -1
package/dist/exception.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ type ExceptionStatic<TParams extends ExceptionParams, TOptions extends Exception
|
|
|
24
24
|
Instance: BaseException<TParams, TOptions>;
|
|
25
25
|
};
|
|
26
26
|
type ExceptionConstructor<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = new (...args: ExceptionConstructorArgs<TParams, TOptions>) => BaseException<TParams, TOptions>;
|
|
27
|
-
type ExceptionType<TParams extends ExceptionParams, TOptions extends ExceptionOptions, TStaticProps = unknown> = ExceptionConstructor<TParams, TOptions> & ExceptionStatic<TParams, TOptions> & TStaticProps;
|
|
27
|
+
type ExceptionType<TParams extends ExceptionParams = ExceptionParams, TOptions extends ExceptionOptions = ExceptionOptions, TStaticProps = unknown> = ExceptionConstructor<TParams, TOptions> & ExceptionStatic<TParams, TOptions> & TStaticProps;
|
|
28
28
|
declare abstract class BaseException<TParams extends ExceptionParams, TOptions extends ExceptionOptions> extends Error {
|
|
29
29
|
cause: TOptions['cause'];
|
|
30
30
|
details: TOptions['details'];
|
|
@@ -32,6 +32,9 @@ declare abstract class BaseException<TParams extends ExceptionParams, TOptions e
|
|
|
32
32
|
constructor(message?: string, options?: TOptions);
|
|
33
33
|
toAsyncErr(): ResultAsync<never, this>;
|
|
34
34
|
toErr(): Result<never, this>;
|
|
35
|
+
toString(): string;
|
|
36
|
+
private extractCauses;
|
|
37
|
+
private formatError;
|
|
35
38
|
}
|
|
36
39
|
type CoreExceptionConstructor = ToAbstractConstructor<ExceptionConstructor<ExceptionParams, ExceptionOptions>>;
|
|
37
40
|
declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOptions extends ExceptionOptions, TStaticMethods extends {
|
|
@@ -97,6 +100,6 @@ declare const OutOfRangeException: ExceptionType<{
|
|
|
97
100
|
};
|
|
98
101
|
}>;
|
|
99
102
|
}>;
|
|
100
|
-
export type { ExceptionConstructor };
|
|
103
|
+
export type { ExceptionConstructor, ExceptionConstructorArgs, ExceptionName, ExceptionOptions, ExceptionParams, ExceptionStatic, ExceptionType };
|
|
101
104
|
export { BaseException, ExceptionBuilder, OutOfRangeException, ValueException };
|
|
102
105
|
//# sourceMappingURL=exception.d.ts.map
|
package/dist/exception.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAKzD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,aAAa,GAAG,GAAG,MAAM,WAAW,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,CAAC,QAAQ,GAAG,GAAG,IAAI;IACrC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM,CAAC;IACnD,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,KAAK,wBAAwB,CAAC,OAAO,SAAS,eAAe,EAAE,QAAQ,SAAS,g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E,CAAC"}
|
package/dist/exception.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
2
|
/* eslint-disable no-dupe-class-members */
|
|
3
|
+
import cleanStack from 'clean-stack';
|
|
4
|
+
import extractStack from 'extract-stack';
|
|
3
5
|
import { err, errAsync, Result, ResultAsync } from 'neverthrow';
|
|
6
|
+
import stringifyObject from 'stringify-object';
|
|
4
7
|
import { objectify } from './object.js';
|
|
8
|
+
import { indentLines } from './string.js';
|
|
5
9
|
class BaseException extends Error {
|
|
6
10
|
cause;
|
|
7
11
|
details;
|
|
@@ -16,6 +20,34 @@ class BaseException extends Error {
|
|
|
16
20
|
toErr() {
|
|
17
21
|
return err(this);
|
|
18
22
|
}
|
|
23
|
+
toString() {
|
|
24
|
+
const result = [];
|
|
25
|
+
this.extractCauses(this).forEach((error) => {
|
|
26
|
+
result.push(this.formatError(error));
|
|
27
|
+
result.push('\nThe above exception was the cause of the following exception:\n');
|
|
28
|
+
});
|
|
29
|
+
result.push(this.formatError(this));
|
|
30
|
+
return result.join('\n');
|
|
31
|
+
}
|
|
32
|
+
extractCauses(error) {
|
|
33
|
+
const errors = [];
|
|
34
|
+
let cause = error.cause;
|
|
35
|
+
while (cause instanceof Error) {
|
|
36
|
+
errors.push(cause);
|
|
37
|
+
cause = cause.cause;
|
|
38
|
+
}
|
|
39
|
+
return errors.toReversed();
|
|
40
|
+
}
|
|
41
|
+
formatError(error) {
|
|
42
|
+
const result = [`${error.name}: ${error.message}`];
|
|
43
|
+
extractStack.lines(cleanStack(error.stack, { pretty: true })).forEach((line) => {
|
|
44
|
+
result.push(` at ${line}`);
|
|
45
|
+
});
|
|
46
|
+
if (error.details) {
|
|
47
|
+
result.push(indentLines(`details: ${stringifyObject(error.details, { indent: ' ' })}`, 4));
|
|
48
|
+
}
|
|
49
|
+
return result.join('\n');
|
|
50
|
+
}
|
|
19
51
|
}
|
|
20
52
|
class ExceptionBuilder {
|
|
21
53
|
base = BaseException;
|
package/dist/string.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare function capitalize<T extends string>(s: T): Capitalize<T>;
|
|
|
6
6
|
export declare function toLowerCase<T extends string>(s: T): Lowercase<T>;
|
|
7
7
|
export declare function toUpperCase<T extends string>(s: T): Uppercase<T>;
|
|
8
8
|
export declare function format(s: string, ...args: Exclude<Primitive, symbol>[]): string;
|
|
9
|
+
export declare function indentLines(s: string, count: number): string;
|
|
9
10
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAErE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAIrE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAK/E"}
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAErE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAIrE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAK/E;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5D"}
|
package/dist/string.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douglasneuroinformatics/libjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"packageManager": "pnpm@10.3.0",
|
|
6
6
|
"description": "A collection of utility functions and types for Node.js and the browser",
|
|
7
7
|
"author": "Joshua Unrau",
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
"zod": "^3.22.6"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"clean-stack": "^5.2.0",
|
|
38
|
+
"extract-stack": "^3.0.0",
|
|
39
|
+
"stringify-object": "^5.0.0",
|
|
37
40
|
"type-fest": "^4.34.1"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
@@ -42,6 +45,7 @@
|
|
|
42
45
|
"@douglasneuroinformatics/semantic-release": "^0.2.1",
|
|
43
46
|
"@douglasneuroinformatics/tsconfig": "^1.0.2",
|
|
44
47
|
"@types/node": "22.x",
|
|
48
|
+
"@types/stringify-object": "^4.0.5",
|
|
45
49
|
"@vitest/coverage-v8": "^3.0.5",
|
|
46
50
|
"concurrently": "^9.1.2",
|
|
47
51
|
"eslint": "^9.20.1",
|