@douglasneuroinformatics/libjs 1.4.0 → 1.5.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.
@@ -0,0 +1,34 @@
1
+ import type { IsNever, RequiredKeysOf, Simplify } from 'type-fest';
2
+ type ExceptionOptions = Simplify<ErrorOptions & {
3
+ details?: {
4
+ [key: string]: unknown;
5
+ };
6
+ }>;
7
+ type ExceptionParams = {
8
+ message?: string;
9
+ name: string;
10
+ };
11
+ type ExceptionInstance<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = Error & {
12
+ cause: TOptions['cause'];
13
+ details: TOptions['details'];
14
+ name: TParams['name'];
15
+ };
16
+ type ExceptionConstructorArgs<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = IsNever<RequiredKeysOf<TOptions>> extends true ? [message?: string, options?: TOptions] : TParams extends {
17
+ message: string;
18
+ } ? [TOptions] : [message: string, options: TOptions];
19
+ type ExceptionConstructor<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = new (...args: ExceptionConstructorArgs<TParams, TOptions>) => ExceptionInstance<TParams, TOptions>;
20
+ declare abstract class BaseException<TParams extends ExceptionParams, TOptions extends ExceptionOptions> extends Error implements ExceptionInstance<TParams, TOptions> {
21
+ cause: TOptions['cause'];
22
+ details: TOptions['details'];
23
+ abstract name: TParams['name'];
24
+ constructor(message?: string, options?: TOptions);
25
+ }
26
+ declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOptions extends ExceptionOptions> {
27
+ private params?;
28
+ build(): [TParams] extends [ExceptionParams] ? ExceptionConstructor<TParams, TOptions> : never;
29
+ setOptionsType<TUpdatedOptions extends ExceptionOptions>(): ExceptionBuilder<TParams, TUpdatedOptions>;
30
+ setParams<const TUpdatedParams extends NonNullable<TParams>>(params: TUpdatedParams): ExceptionBuilder<TUpdatedParams, TOptions>;
31
+ }
32
+ export type { ExceptionConstructor, ExceptionInstance };
33
+ export { BaseException, ExceptionBuilder };
34
+ //#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C,CAAC;AAE1C,uBAAe,aAAa,CAAC,OAAO,SAAS,eAAe,EAAE,QAAQ,SAAS,gBAAgB,CAC7F,SAAQ,KACR,YAAW,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC;IAE/B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpC,SAAyB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;gBAEnC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ;CAKjD;AAED,cAAM,gBAAgB,CAAC,OAAO,SAAS,eAAe,GAAG,SAAS,EAAE,QAAQ,SAAS,gBAAgB;IACnG,OAAO,CAAC,MAAM,CAAC,CAAU;IAEzB,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,KAAK;IAe9F,cAAc,CAAC,eAAe,SAAS,gBAAgB,KAC3B,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC;IAGtE,SAAS,CAAC,KAAK,CAAC,cAAc,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,cAAc,GAEvD,gBAAgB,CAAC,cAAc,EAAE,QAAQ,CAAC;CAEvE;AAED,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,34 @@
1
+ /* eslint-disable no-dupe-class-members */
2
+ class BaseException extends Error {
3
+ cause;
4
+ details;
5
+ constructor(message, options) {
6
+ super(message);
7
+ this.cause = options?.cause;
8
+ this.details = options?.details;
9
+ }
10
+ }
11
+ class ExceptionBuilder {
12
+ params;
13
+ build() {
14
+ if (!this.params) {
15
+ throw new Error('Cannot build exception: params is undefined');
16
+ }
17
+ const params = this.params;
18
+ return class extends BaseException {
19
+ name = params.name;
20
+ constructor(...args) {
21
+ const [message, options] = (params.message ? [params.message, args[0]] : args);
22
+ super(message, options);
23
+ }
24
+ };
25
+ }
26
+ setOptionsType() {
27
+ return this;
28
+ }
29
+ setParams(params) {
30
+ this.params = params;
31
+ return this;
32
+ }
33
+ }
34
+ export { BaseException, ExceptionBuilder };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './array.js';
2
2
  export * from './datetime.js';
3
+ export * from './exception.js';
3
4
  export * from './json.js';
4
5
  export * from './number.js';
5
6
  export * from './object.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './array.js';
2
2
  export * from './datetime.js';
3
+ export * from './exception.js';
3
4
  export * from './json.js';
4
5
  export * from './number.js';
5
6
  export * from './object.js';
@@ -1 +1 @@
1
- {"root":["../src/array.ts","../src/datetime.ts","../src/index.ts","../src/json.ts","../src/number.ts","../src/object.ts","../src/random.ts","../src/range.ts","../src/string.ts","../src/types.ts","../src/zod.ts"],"version":"5.6.3"}
1
+ {"root":["../src/array.ts","../src/datetime.ts","../src/exception.ts","../src/index.ts","../src/json.ts","../src/number.ts","../src/object.ts","../src/random.ts","../src/range.ts","../src/string.ts","../src/types.ts","../src/zod.ts"],"version":"5.6.3"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libjs",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.5.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",
@@ -21,7 +21,8 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "build": "rm -rf dist && tsc -b tsconfig.build.json",
24
- "build:docs": "typedoc",
24
+ "docs:build": "typedoc",
25
+ "docs:dev": "concurrently \"typedoc --watch\" \"http-server docs -c-1\"",
25
26
  "format": "prettier --write src",
26
27
  "lint": "tsc --noEmit && eslint --fix src",
27
28
  "prepare": "husky",
@@ -33,16 +34,20 @@
33
34
  "zod": "^3.22.6"
34
35
  },
35
36
  "devDependencies": {
36
- "@douglasneuroinformatics/eslint-config": "^5.2.4",
37
+ "@douglasneuroinformatics/eslint-config": "^5.3.1",
37
38
  "@douglasneuroinformatics/prettier-config": "^0.0.1",
38
39
  "@douglasneuroinformatics/semantic-release": "^0.2.1",
39
40
  "@douglasneuroinformatics/tsconfig": "^1.0.2",
40
41
  "@types/node": "22.x",
41
42
  "@vitest/coverage-v8": "^3.0.5",
43
+ "concurrently": "^9.1.2",
42
44
  "eslint": "^9.20.1",
45
+ "http-server": "^14.1.1",
43
46
  "husky": "^9.1.7",
44
47
  "prettier": "^3.5.0",
45
- "typedoc": "^0.27.7",
48
+ "typedoc": "^0.27.8",
49
+ "typedoc-material-theme": "^1.3.0",
50
+ "typedoc-plugin-zod": "^1.3.1",
46
51
  "typescript": "5.6.x",
47
52
  "vitest": "^3.0.5"
48
53
  },