Skip to content

Commit

Permalink
feat: export Reason enum
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Apr 20, 2024
1 parent 46307d1 commit f1afaf0
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/assertions/endsWith/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EndsWith } from "@assertions/endsWith/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/includes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Includes } from "@assertions/includes/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/integer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Integer } from "@assertions/integer/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/isArray/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/isObject/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ObjectUnknown } from "@assertions/isObject/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/length/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Length } from "@assertions/length/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/maxLength/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MaxLength } from "@assertions/maxLength/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/maxValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MaxValue } from "@assertions/maxValue/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/minLength/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MinLength } from "@assertions/minLength/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/minValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MinValue } from "@assertions/minValue/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/modulo/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Modulo } from "@assertions/modulo/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

export const modulo =
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/notLength/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NotLength } from "@assertions/notLength/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/notValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NotValue } from "@assertions/notValue/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/or/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { InferOrSchema, OrSchema } from "@assertions/or/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/rangeLength/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RangeLength } from "@assertions/rangeLength/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/rangeValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RangeValue } from "@assertions/rangeValue/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/regex/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Regex } from "@assertions/regex/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/startsWith/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { StartsWith } from "@assertions/startsWith/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/type/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/union/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
3 changes: 2 additions & 1 deletion src/assertions/value/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Value } from "@assertions/value/types";
import { Reason, error } from "@error";
import { Reason } from "@constants";
import { error } from "@error";
import type { Assertion } from "@the-minimal/types";

/**
Expand Down
30 changes: 30 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// CRC-16/ARC decimal error names
export enum Reason {
type = 49711,
or = 54701,
union = 9197,

integer = 58693,
modulo = 29375,

regex = 27324,
startsWith = 15577,
endsWith = 47266,

includes = 30945,

isArray = 7069,
isObject = 25174,

value = 37360,
notValue = 16483,
minValue = 28487,
maxValue = 22988,
rangeValue = 45807,

length = 48590,
notLength = 53343,
minLength = 52080,
maxLength = 44038,
rangeLength = 30124,
}
33 changes: 2 additions & 31 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
import type { Reason } from "@constants";

export const error = (reason: Reason) => {
throw reason;
};

// CRC-16/ARC decimal error names
export enum Reason {
type = 49711,
or = 54701,
union = 9197,

integer = 58693,
modulo = 29375,

regex = 27324,
startsWith = 15577,
endsWith = 47266,

includes = 30945,

isArray = 7069,
isObject = 25174,

value = 37360,
notValue = 16483,
minValue = 28487,
maxValue = 22988,
rangeValue = 45807,

length = 48590,
notLength = 53343,
minLength = 52080,
maxLength = 44038,
rangeLength = 30124,
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./types";
export * from "./constants";
export * from "./assertions";

0 comments on commit f1afaf0

Please sign in to comment.