@douglasneuroinformatics/libjs 1.5.1 → 2.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,WAEtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,WAE3C"}
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAErD"}
@@ -1,3 +1,5 @@
1
+ import type { Result } from 'neverthrow';
2
+ import { OutOfRangeException } from './exception.js';
1
3
  export type Duration = {
2
4
  days: number;
3
5
  hours: number;
@@ -43,13 +45,13 @@ export declare function yearsPassed(date: Date): number;
43
45
  * await sleep(5);
44
46
  * ```
45
47
  */
46
- export declare function sleep(seconds: number): Promise<unknown>;
48
+ export declare function sleep(seconds: number): Promise<void>;
47
49
  /**
48
50
  * Parses a given duration in milliseconds into an object representing the duration in days, hours, minutes, seconds, and milliseconds.
49
51
  *
50
52
  * @param milliseconds - The duration in milliseconds to be parsed.
51
- * @returns An object of type `Duration` representing the parsed duration.
52
- * @throws Will throw an error if the input duration is negative.
53
+ * @returns An result of type `Duration` representing the parsed duration. This will return an OutOfRangeException
54
+ * if the input is negative.
53
55
  */
54
- export declare function parseDuration(milliseconds: number): Duration;
56
+ export declare function parseDuration(milliseconds: number): Result<Duration, typeof OutOfRangeException.Instance>;
55
57
  //# sourceMappingURL=datetime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,QAAQ,mEAMV,CAAC;AAEZ;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,UAE1C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,oBAE1C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,CAY5D"}
1
+ {"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,QAAQ,mEAMV,CAAC;AAEZ;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAYzG"}
package/dist/datetime.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { err, ok } from 'neverthrow';
2
+ import { OutOfRangeException } from './exception.js';
1
3
  /** A map that associates time units with their corresponding values in milliseconds */
2
4
  export const TIME_MAP = new Map([
3
5
  ['day', 24 * 60 * 60 * 1000],
@@ -55,12 +57,12 @@ export async function sleep(seconds) {
55
57
  * Parses a given duration in milliseconds into an object representing the duration in days, hours, minutes, seconds, and milliseconds.
56
58
  *
57
59
  * @param milliseconds - The duration in milliseconds to be parsed.
58
- * @returns An object of type `Duration` representing the parsed duration.
59
- * @throws Will throw an error if the input duration is negative.
60
+ * @returns An result of type `Duration` representing the parsed duration. This will return an OutOfRangeException
61
+ * if the input is negative.
60
62
  */
61
63
  export function parseDuration(milliseconds) {
62
64
  if (0 > milliseconds) {
63
- throw new Error(`Cannot parse negative length of time: ${milliseconds}`);
65
+ return err(OutOfRangeException.forNonPositive(milliseconds));
64
66
  }
65
67
  const duration = {};
66
68
  let remaining = milliseconds;
@@ -69,5 +71,5 @@ export function parseDuration(milliseconds) {
69
71
  duration[`${unit}s`] = count;
70
72
  remaining %= value;
71
73
  });
72
- return duration;
74
+ return ok(duration);
73
75
  }
@@ -1,34 +1,99 @@
1
- import type { IsNever, RequiredKeysOf, Simplify } from 'type-fest';
2
- type ExceptionOptions = Simplify<ErrorOptions & {
1
+ import { Err } from 'neverthrow';
2
+ import type { IsNever, RequiredKeysOf } from 'type-fest';
3
+ import type { SingleKeyMap, ToAbstractConstructor } from './types.js';
4
+ type ExceptionName = `${string}Exception`;
5
+ type ExceptionOptions = {
6
+ cause?: unknown;
3
7
  details?: {
4
8
  [key: string]: unknown;
5
9
  };
6
- }>;
7
- type ExceptionParams = {
8
- message?: string;
9
- name: string;
10
10
  };
11
- type ExceptionInstance<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = Error & {
12
- cause: TOptions['cause'];
13
- details: TOptions['details'];
14
- name: TParams['name'];
11
+ type ExceptionParams<TDetails = any> = {
12
+ message?: ((details: TDetails) => string) | string;
13
+ name: ExceptionName;
15
14
  };
16
15
  type ExceptionConstructorArgs<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = IsNever<RequiredKeysOf<TOptions>> extends true ? [message?: string, options?: TOptions] : TParams extends {
17
- message: string;
16
+ message: ((details: any) => string) | string;
18
17
  } ? [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> {
18
+ type ExceptionStatic<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = {
19
+ /** return an instance of the exception wrapped in a neverthrow Error object */
20
+ asErr(...args: ExceptionConstructorArgs<TParams, TOptions>): Err<never, BaseException<TParams, TOptions>>;
21
+ /** inference-only property that will be undefined at runtime */
22
+ Instance: BaseException<TParams, TOptions>;
23
+ };
24
+ type ExceptionConstructor<TParams extends ExceptionParams, TOptions extends ExceptionOptions> = new (...args: ExceptionConstructorArgs<TParams, TOptions>) => BaseException<TParams, TOptions>;
25
+ type ExceptionType<TParams extends ExceptionParams, TOptions extends ExceptionOptions, TStaticProps = unknown> = ExceptionConstructor<TParams, TOptions> & ExceptionStatic<TParams, TOptions> & TStaticProps;
26
+ declare abstract class BaseException<TParams extends ExceptionParams, TOptions extends ExceptionOptions> extends Error {
21
27
  cause: TOptions['cause'];
22
28
  details: TOptions['details'];
23
29
  abstract name: TParams['name'];
24
30
  constructor(message?: string, options?: TOptions);
31
+ toErr(): Err<never, this>;
25
32
  }
26
- declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOptions extends ExceptionOptions> {
33
+ type CoreExceptionConstructor = ToAbstractConstructor<ExceptionConstructor<ExceptionParams, ExceptionOptions>>;
34
+ declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOptions extends ExceptionOptions, TStaticMethods extends {
35
+ [key: string]: unknown;
36
+ }> {
37
+ private base;
27
38
  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>;
39
+ private staticMethods;
40
+ build(): [TParams] extends [ExceptionParams] ? SingleKeyMap<TParams['name'], ExceptionType<NonNullable<TParams>, TOptions, TStaticMethods>> : never;
41
+ extend(constructor: CoreExceptionConstructor): this;
42
+ setOptionsType<TUpdatedOptions extends ExceptionOptions>(): ExceptionBuilder<TParams, TUpdatedOptions, TStaticMethods>;
43
+ setParams<const TUpdatedParams extends ExceptionParams<TOptions['details']>>(params: TUpdatedParams): ExceptionBuilder<TUpdatedParams, TOptions, TStaticMethods>;
44
+ setStaticMethod<TName extends string, TMethod extends (this: ExceptionConstructor<NonNullable<TParams>, TOptions>, ...args: any[]) => any>(name: TName, method: TMethod): ExceptionBuilder<TParams, TOptions, TStaticMethods & {
45
+ [K in TName]: TMethod;
46
+ }>;
31
47
  }
32
- export type { ExceptionConstructor, ExceptionInstance };
33
- export { BaseException, ExceptionBuilder };
48
+ declare const ValueException: ExceptionType<{
49
+ readonly name: "ValueException";
50
+ }, ExceptionOptions, {
51
+ [key: string]: unknown;
52
+ }>;
53
+ declare const OutOfRangeException: ExceptionType<{
54
+ readonly message: ({ max, min, value }: {
55
+ max: number;
56
+ min: number;
57
+ value: number;
58
+ }) => string;
59
+ readonly name: "OutOfRangeException";
60
+ }, {
61
+ details: {
62
+ max: number;
63
+ min: number;
64
+ value: number;
65
+ };
66
+ }, {
67
+ [key: string]: unknown;
68
+ } & {
69
+ forNonPositive: (this: ExceptionConstructor<{
70
+ readonly message: ({ max, min, value }: {
71
+ max: number;
72
+ min: number;
73
+ value: number;
74
+ }) => string;
75
+ readonly name: "OutOfRangeException";
76
+ }, {
77
+ details: {
78
+ max: number;
79
+ min: number;
80
+ value: number;
81
+ };
82
+ }>, value: number) => BaseException<{
83
+ readonly message: ({ max, min, value }: {
84
+ max: number;
85
+ min: number;
86
+ value: number;
87
+ }) => string;
88
+ readonly name: "OutOfRangeException";
89
+ }, {
90
+ details: {
91
+ max: number;
92
+ min: number;
93
+ value: number;
94
+ };
95
+ }>;
96
+ }>;
97
+ export type { ExceptionConstructor };
98
+ export { BaseException, ExceptionBuilder, OutOfRangeException, ValueException };
34
99
  //# sourceMappingURL=exception.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEnE,KAAK,gBAAgB,GAAG,QAAQ,CAC9B,YAAY,GAAG;IACb,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH,CACF,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,CAAC,OAAO,SAAS,eAAe,EAAE,QAAQ,SAAS,gBAAgB,IAAI,KAAK,GAAG;IACnG,KAAK,EAA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,GAAG;SAAG,CAAC,IAAI,KAAK,GAAG,OAAO;KAAE,CAAC;CAIjH;AAED,QAAA,MAAQ,cAAc;;;;EAAyE,CAAC;AAEhG,QAAA,MAAQ,mBAAmB;;aAES,MAAM;aAAO,MAAM;eAAS,MAAM;;;;aAAzC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;;;;;;iBAApC,MAAM;iBAAO,MAAM;mBAAS,MAAM;;;;iBAAzC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE;eAKlB,MAAM;;iBALxB,MAAM;iBAAO,MAAM;mBAAS,MAAM;;;;iBAAzC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE;;EAQ9D,CAAC;AAEX,YAAY,EAAE,oBAAoB,EAAE,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAC"}
package/dist/exception.js CHANGED
@@ -1,4 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
1
2
  /* eslint-disable no-dupe-class-members */
3
+ import { Err, err } from 'neverthrow';
4
+ import { objectify } from './object.js';
2
5
  class BaseException extends Error {
3
6
  cause;
4
7
  details;
@@ -7,21 +10,43 @@ class BaseException extends Error {
7
10
  this.cause = options?.cause;
8
11
  this.details = options?.details;
9
12
  }
13
+ toErr() {
14
+ return err(this);
15
+ }
10
16
  }
11
17
  class ExceptionBuilder {
18
+ base = BaseException;
12
19
  params;
20
+ staticMethods = {};
13
21
  build() {
14
22
  if (!this.params) {
15
23
  throw new Error('Cannot build exception: params is undefined');
16
24
  }
17
25
  const params = this.params;
18
- return class extends BaseException {
26
+ const constructor = class extends this.base {
27
+ static Instance;
19
28
  name = params.name;
20
29
  constructor(...args) {
21
- const [message, options] = (params.message ? [params.message, args[0]] : args);
30
+ let message, options;
31
+ if (params.message) {
32
+ options = args[0];
33
+ message = typeof params.message === 'function' ? params.message(options.details) : params.message;
34
+ }
35
+ else {
36
+ message = args[0];
37
+ options = args[1];
38
+ }
22
39
  super(message, options);
23
40
  }
41
+ static asErr(...args) {
42
+ return new this(...args).toErr();
43
+ }
24
44
  };
45
+ return objectify(params.name, Object.assign(constructor, this.staticMethods));
46
+ }
47
+ extend(constructor) {
48
+ this.base = constructor;
49
+ return this;
25
50
  }
26
51
  setOptionsType() {
27
52
  return this;
@@ -30,5 +55,21 @@ class ExceptionBuilder {
30
55
  this.params = params;
31
56
  return this;
32
57
  }
58
+ setStaticMethod(name, method) {
59
+ this.staticMethods = { ...this.staticMethods, [name]: method };
60
+ return this;
61
+ }
33
62
  }
34
- export { BaseException, ExceptionBuilder };
63
+ const { ValueException } = new ExceptionBuilder().setParams({ name: 'ValueException' }).build();
64
+ const { OutOfRangeException } = new ExceptionBuilder()
65
+ .extend(ValueException)
66
+ .setOptionsType()
67
+ .setParams({
68
+ message: ({ max, min, value }) => `Value ${value} is out of range (${min} - ${max})`,
69
+ name: 'OutOfRangeException'
70
+ })
71
+ .setStaticMethod('forNonPositive', function (value) {
72
+ return new this({ details: { max: Infinity, min: 0, value } });
73
+ })
74
+ .build();
75
+ export { BaseException, ExceptionBuilder, OutOfRangeException, ValueException };
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AA6BA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,WAelE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,WAOhD"}
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AA6BA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAe5E;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAO1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,WAK3C;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,MAAM,CAOrE;AAED,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAElD"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAKrD;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,MAAM,CAOrE;AAED,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAElD"}
package/dist/object.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { SingleKeyMap } from './types.js';
1
2
  export type ReadonlyDeep<T extends object> = Readonly<{
2
3
  [K in keyof T]: T[K] extends object ? ReadonlyDeep<T[K]> : T[K];
3
4
  }>;
@@ -26,7 +27,6 @@ export declare function isAllUndefined<T extends {
26
27
  }>(obj: T): boolean;
27
28
  export declare function filterObject<T extends {
28
29
  [key: string]: unknown;
29
- }>(obj: T, callback: (value: T[keyof T], key: keyof T) => boolean): {
30
- [k: string]: unknown;
31
- };
30
+ }>(obj: T, callback: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
31
+ export declare function objectify<K extends PropertyKey, V>(key: K, value: V): SingleKeyMap<K, V>;
32
32
  //# sourceMappingURL=object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAAC;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC,CAAC;AAEH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,SAAS,OAAO,GAAG,IAAI,EAC3E,GAAG,EAAE,CAAC,EACN,OAAO,CAAC,EAAE;IAAE,YAAY,EAAE,SAAS,CAAA;CAAE,GACpC,SAAS,SAAS,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAQ9C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAGxD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAUjF;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,GAAG,EAAE,CAAC,WAE1E;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAC/D,GAAG,EAAE,CAAC,EACN,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,CAA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,EACN,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,OAAO,GACrD,OAAO,CAAC,CAAC,CAAC,CAIZ;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAExF"}
package/dist/object.js CHANGED
@@ -41,3 +41,6 @@ export function isAllUndefined(obj) {
41
41
  export function filterObject(obj, callback) {
42
42
  return Object.fromEntries(Object.entries(obj).filter(([key, value]) => callback(value, key)));
43
43
  }
44
+ export function objectify(key, value) {
45
+ return { [key]: value };
46
+ }
package/dist/random.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import type { Result } from 'neverthrow';
2
+ import { ValueException } from './exception.js';
1
3
  /** Returns a random integer between `min` (inclusive) and `max` (not inclusive) */
2
- export declare function randomInt(min: number, max: number): number;
4
+ export declare function randomInt(min: number, max: number): Result<number, typeof ValueException.Instance>;
3
5
  /** Returns a random date between `start` and `end` (both inclusive) */
4
- export declare function randomDate(start: Date, end: Date): Date;
6
+ export declare function randomDate(start: Date, end: Date): Result<Date, typeof ValueException.Instance>;
5
7
  /** Returns a random value from the array */
6
- export declare function randomValue<T>(arr: T[]): T | undefined;
8
+ export declare function randomValue<T>(arr: T[]): Result<T, typeof ValueException.Instance>;
7
9
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAKjD;AAED,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,QAKhD;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,iBAKtC"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,cAAc,CAAC,QAAQ,CAAC,CAKlG;AAED,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,OAAO,cAAc,CAAC,QAAQ,CAAC,CAO/F;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,cAAc,CAAC,QAAQ,CAAC,CAKlF"}
package/dist/random.js CHANGED
@@ -1,21 +1,23 @@
1
+ import { ok } from 'neverthrow';
2
+ import { ValueException } from './exception.js';
1
3
  /** Returns a random integer between `min` (inclusive) and `max` (not inclusive) */
2
4
  export function randomInt(min, max) {
3
5
  if (min >= max) {
4
- throw new Error(`Min value '${min}' must not be greater than or equal to the max value '${max}'`);
6
+ return ValueException.asErr(`Min value '${min}' must not be greater than or equal to the max value '${max}'`);
5
7
  }
6
- return Math.floor(Math.random() * (max - min)) + min;
8
+ return ok(Math.floor(Math.random() * (max - min)) + min);
7
9
  }
8
10
  /** Returns a random date between `start` and `end` (both inclusive) */
9
11
  export function randomDate(start, end) {
10
12
  if (start > end) {
11
- throw new Error(`Start date '${start.toISOString()}' cannot be greater than end date '${end.toISOString()}'`);
13
+ return ValueException.asErr(`Start date '${start.toISOString()}' cannot be greater than end date '${end.toISOString()}'`);
12
14
  }
13
- return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
15
+ return ok(new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())));
14
16
  }
15
17
  /** Returns a random value from the array */
16
18
  export function randomValue(arr) {
17
19
  if (arr.length === 0) {
18
- throw new Error('Cannot select random value from array of length zero');
20
+ return ValueException.asErr('Cannot select random value from array of length zero');
19
21
  }
20
- return arr[randomInt(0, arr.length)];
22
+ return randomInt(0, arr.length).map((index) => arr[index]);
21
23
  }
package/dist/range.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import type { Result } from 'neverthrow';
2
+ import { ValueException } from './exception.js';
1
3
  /** Return an array of integers between 0 (inclusive) and `end` (not inclusive) */
2
- export declare function range(end: number): readonly number[];
4
+ export declare function range(end: number): Result<readonly number[], typeof ValueException.Instance>;
3
5
  /** Return an array of integers between `start` (inclusive) and `end` (not inclusive) */
4
- export declare function range(start: number, end: number): readonly number[];
6
+ export declare function range(start: number, end: number): Result<readonly number[], typeof ValueException.Instance>;
5
7
  //# sourceMappingURL=range.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAEtD,wFAAwF;AACxF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,kFAAkF;AAClF,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AAE9F,wFAAwF;AACxF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC"}
package/dist/range.js CHANGED
@@ -1,12 +1,14 @@
1
+ import { ok } from 'neverthrow';
2
+ import { ValueException } from './exception.js';
1
3
  export function range(...args) {
2
4
  const start = args.length === 2 ? args[0] : 0;
3
5
  const end = args.length === 2 ? args[1] : args[0];
4
6
  if (start >= end) {
5
- throw new Error(`End of range '${end}' must be greater than start '${start}'`);
7
+ return ValueException.asErr(`End of range '${end}' must be greater than start '${start}'`);
6
8
  }
7
9
  const values = [];
8
10
  for (let i = start; i < end; i++) {
9
11
  values.push(i);
10
12
  }
11
- return values;
13
+ return ok(values);
12
14
  }
@@ -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,GACiB,SAAS,CAAC,CAAC,CAAC,CACnF;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAG2C,SAAS,CAAC,CAAC,CAAC,CAC7G;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GACE,YAAY,CAAC,CAAC,CAAC,CACnE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GACI,UAAU,CAAC,CAAC,CAAC,CACjE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GACtB,SAAS,CAAC,CAAC,CAAC,CACvC;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GACtB,SAAS,CAAC,CAAC,CAAC,CACvC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,UAKtE"}
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"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IfNever } from 'type-fest';
1
+ import type { IfNever, IsStringLiteral } from 'type-fest';
2
2
  /**
3
3
  * Return whether `T` or any record nested therein contains the key `K`
4
4
  *
@@ -16,4 +16,9 @@ export type HasNestedKey<T, P extends string> = T extends {
16
16
  } ? IfNever<keyof {
17
17
  [K in keyof T as K extends P ? K : HasNestedKey<T[K], P> extends true ? K : never]: never;
18
18
  }, false, true> : T extends (infer U)[] ? HasNestedKey<U, P> : false;
19
+ export type ToAbstractConstructor<T extends new (...args: any[]) => any> = T extends new (...args: infer TArgs extends any[]) => infer TReturn ? abstract new (...args: TArgs) => TReturn : never;
20
+ export type IsUnion<T, U = T> = (T extends U ? (U extends T ? true : false) : never) extends true ? false : true;
21
+ export type SingleKeyMap<K extends PropertyKey, V> = IsStringLiteral<K> extends true ? IsUnion<K> extends false ? {
22
+ [key in K]: V;
23
+ } : never : never;
19
24
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS;IACxD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,GACG,OAAO,CACL,MAAM;KACH,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK;CAC1F,EACD,KAAK,EACL,IAAI,CACL,GACD,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAClB,KAAK,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,E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@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libjs",
3
3
  "type": "module",
4
- "version": "1.5.1",
4
+ "version": "2.0.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",
@@ -29,10 +29,13 @@
29
29
  "test": "vitest run",
30
30
  "test:coverage": "vitest run --coverage"
31
31
  },
32
- "dependencies": {
33
- "type-fest": "^4.34.1",
32
+ "peerDependencies": {
33
+ "neverthrow": "^8.2.0",
34
34
  "zod": "^3.22.6"
35
35
  },
36
+ "dependencies": {
37
+ "type-fest": "^4.34.1"
38
+ },
36
39
  "devDependencies": {
37
40
  "@douglasneuroinformatics/eslint-config": "^5.3.1",
38
41
  "@douglasneuroinformatics/prettier-config": "^0.0.1",