Skip to content

Commit

Permalink
perf(constants): remove top-level exported const enum
Browse files Browse the repository at this point in the history
Because tree-shaking is not available if there are imported const enum and top-level execution pair
  • Loading branch information
TomokiMiyauci committed May 25, 2023
1 parent 1c3b569 commit c971484
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
20 changes: 7 additions & 13 deletions combinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ import { NotValidator } from "./validators/operators/not.ts";
import { OrValidator } from "./validators/operators/or.ts";
import { TypeValidator } from "./validators/operators/typeof.ts";
import { ValidDateValidator } from "./validators/date/valid_date.ts";
import {
Error,
Int16Range,
Int32Range,
Int8Range,
UnsignedUpper,
} from "./constants.ts";
import { Error } from "./constants.ts";

export function message(this: Display, { input }: { input: unknown }): string {
return interpolate(Error.ShouldBeBut, [this, typeof input]);
Expand Down Expand Up @@ -136,27 +130,27 @@ export const unique = /* @__PURE__ */ new UniqueValidator().expect(({ item }) =>
export const int = /* @__PURE__ */ new IntegerValidator().expect(shouldBeBut);
export const int8 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(Int8Range.Bottom, Int8Range.Upper),
/* @__PURE__ */ between(-127, 128),
);
export const int16 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(Int16Range.Bottom, Int16Range.Upper),
/* @__PURE__ */ between(-32768, 32767),
);
export const int32 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(Int32Range.Bottom, Int32Range.Upper),
/* @__PURE__ */ between(-2147483648, 2147483647),
);
export const uint8 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(0, UnsignedUpper.Uint8),
/* @__PURE__ */ between(0, 255),
);
export const uint16 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(0, UnsignedUpper.Uint16),
/* @__PURE__ */ between(0, 65535),
);
export const uint32 = /* @__PURE__ */ and(
int,
/* @__PURE__ */ between(0, UnsignedUpper.Unit32),
/* @__PURE__ */ between(0, 4294967295),
);
export const negative = /* @__PURE__ */ new NegativeNumberValidator().expect(
shouldBeBut,
Expand Down
21 changes: 0 additions & 21 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,3 @@ export const enum Error {
MinCount = "item count should be greater than or equal to {0}, but {1}",
Unique = "item(0) should be unique",
}

export const enum Int8Range {
Bottom = -127,
Upper = 128,
}

export const enum Int16Range {
Bottom = -32768,
Upper = 32767,
}

export const enum Int32Range {
Bottom = -2147483648,
Upper = 2147483647,
}

export const enum UnsignedUpper {
Uint8 = 255,
Uint16 = 65535,
Unit32 = 4294967295,
}

0 comments on commit c971484

Please sign in to comment.