aang 2.0.0-alpha.1 → 2.0.0-alpha.2

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/lib/errors.d.ts CHANGED
@@ -1,9 +1,4 @@
1
- export interface ErrorOptions {
2
- cause?: unknown;
3
- }
4
- export declare abstract class CustomError extends Error {
5
- constructor(name: string, message?: string, options?: ErrorOptions);
6
- }
7
- export declare class UnsafeExtractError extends CustomError {
1
+ import { Exception } from "./exceptions.js";
2
+ export declare class UnsafeExtractError extends Exception {
8
3
  constructor(message: string);
9
4
  }
package/lib/errors.js CHANGED
@@ -1,19 +1,7 @@
1
- export class CustomError extends Error {
2
- constructor(name, message, options) {
3
- super(message, options);
4
- Object.defineProperty(this, "name", {
5
- value: name,
6
- enumerable: false,
7
- configurable: true,
8
- });
9
- Object.setPrototypeOf(this, new.target.prototype);
10
- if ("captureStackTrace" in Error) {
11
- Error.captureStackTrace(this, new.target);
12
- }
13
- }
14
- }
15
- export class UnsafeExtractError extends CustomError {
1
+ import { Exception } from "./exceptions.js";
2
+ export class UnsafeExtractError extends Exception {
16
3
  constructor(message) {
17
- super("UnsafeExtractError", message);
4
+ super(message);
5
+ this.setName("UnsafeExtractError");
18
6
  }
19
7
  }
@@ -0,0 +1,7 @@
1
+ export interface ErrorOptions {
2
+ cause?: unknown;
3
+ }
4
+ export declare abstract class Exception extends Error {
5
+ constructor(message?: string, options?: ErrorOptions);
6
+ protected setName(name: string): void;
7
+ }
@@ -0,0 +1,17 @@
1
+ export class Exception extends Error {
2
+ constructor(message, options) {
3
+ super(message, options);
4
+ this.setName(new.target.name);
5
+ Object.setPrototypeOf(this, new.target.prototype);
6
+ if ("captureStackTrace" in Error) {
7
+ Error.captureStackTrace(this, new.target);
8
+ }
9
+ }
10
+ setName(name) {
11
+ Object.defineProperty(this, "name", {
12
+ value: name,
13
+ enumerable: false,
14
+ configurable: true,
15
+ });
16
+ }
17
+ }
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./errors.js";
1
+ export * from "./exceptions.js";
2
2
  export * from "./option.js";
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./errors.js";
1
+ export * from "./exceptions.js";
2
2
  export * from "./option.js";
package/lib/option.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { Exception } from "./exceptions.js";
1
2
  export type Option<A> = Some<A> | None;
2
3
  declare abstract class OptionMethods {
3
4
  abstract readonly isSome: boolean;
4
5
  abstract readonly isNone: boolean;
5
6
  map<A, B>(this: Option<A>, morphism: (value: A) => B): Option<B>;
6
- unsafeExtract<A>(this: Option<A>, error: Error | string): A;
7
+ unsafeExtract<A>(this: Option<A>, error: Exception | string): A;
7
8
  }
8
9
  declare class Some<out A> extends OptionMethods {
9
10
  readonly value: A;
package/lib/option.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { UnsafeExtractError } from "./errors.js";
2
+ import { Exception } from "./exceptions.js";
2
3
  class OptionMethods {
3
4
  map(morphism) {
4
5
  return this.isSome ? new Some(morphism(this.value)) : none;
@@ -6,7 +7,7 @@ class OptionMethods {
6
7
  unsafeExtract(error) {
7
8
  if (this.isSome)
8
9
  return this.value;
9
- throw error instanceof Error ? error : new UnsafeExtractError(error);
10
+ throw error instanceof Exception ? error : new UnsafeExtractError(error);
10
11
  }
11
12
  }
12
13
  class Some extends OptionMethods {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aang",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "A powerful functional programming library for TypeScript.",
5
5
  "keywords": [
6
6
  "aang",