Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ts-predicate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitruvius-labs/ts-predicate",
"version": "7.0.0",
"version": "7.1.0",
"description": "TypeScript predicates library",
"author": {
"name": "VitruviusLabs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./type-assertion/_index.mjs";
export * from "./type-cast/_index.mjs";
export * from "./type-guard/_index.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./int8.mjs";
export * from "./int16.mjs";
export * from "./int32.mjs";
export * from "./uint8.mjs";
export * from "./uint16.mjs";
export * from "./uint32.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Int16 } from "../../definition/type/integers.mjs";
import { assertInt16 } from "../type-assertion/assert-int16.mjs";

function int16(value: unknown): Int16
{
assertInt16(value);

return value;
}

export { int16 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Int32 } from "../../definition/type/integers.mjs";
import { assertInt32 } from "../type-assertion/assert-int32.mjs";

function int32(value: unknown): Int32
{
assertInt32(value);

return value;
}

export { int32 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Int8 } from "../../definition/type/integers.mjs";
import { assertInt8 } from "../type-assertion/assert-int8.mjs";

function int8(value: unknown): Int8
{
assertInt8(value);

return value;
}

export { int8 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { UInt16 } from "../../definition/type/integers.mjs";
import { assertUInt16 } from "../type-assertion/assert-uint16.mjs";

function uInt16(value: unknown): UInt16
{
assertUInt16(value);

return value;
}

export { uInt16 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { UInt32 } from "../../definition/type/integers.mjs";
import { assertUInt32 } from "../type-assertion/assert-uint32.mjs";

function uInt32(value: unknown): UInt32
{
assertUInt32(value);

return value;
}

export { uInt32 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { UInt8 } from "../../definition/type/integers.mjs";
import { assertUInt8 } from "../type-assertion/assert-uint8.mjs";

function uInt8(value: unknown): UInt8
{
assertUInt8(value);

return value;
}

export { uInt8 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { doesNotThrow, strictEqual, throws } from "node:assert";
import { describe, it } from "node:test";
import { GroupType, consumeValue, getInvertedValues, getValues } from "@vitruvius-labs/testing-ground";
import { type Int16, NoValue, int16 } from "../../../../../src/_index.mjs";
import { IntegerBoundaryEnum } from "../../../../../src/extended/integer/definition/enum/integer-boundary.enum.mjs";

describe("int16", (): void => {
it("should return the provided value when given an integer with the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT16_MIN,
IntegerBoundaryEnum.INT16_MIN + 1,
-1,
0,
1,
IntegerBoundaryEnum.INT16_MAX - 1,
IntegerBoundaryEnum.INT16_MAX,
];

for (const ITEM of VALUES)
{
let result: unknown = NoValue;

const WRAPPER = (): void => {
result = int16(ITEM);
};

doesNotThrow(WRAPPER);

strictEqual(result, ITEM);
}
});

it("should throw when given an integer outside the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT16_MIN - 1,
IntegerBoundaryEnum.INT16_MAX + 1,
];

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int16(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given a non-integer number", (): void => {
const VALUES: Array<unknown> = getValues(GroupType.REAL, GroupType.INFINITY);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int16(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given anything else", (): void => {
const VALUES: Array<unknown> = getInvertedValues(GroupType.NUMBER);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int16(ITEM);
};

throws(WRAPPER);
}
});

it("should narrow the type to an Int16", (): void => {
const WRAPPER = (): void =>
{
consumeValue<Int16>(int16(NoValue));
};

throws(WRAPPER);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { doesNotThrow, strictEqual, throws } from "node:assert";
import { describe, it } from "node:test";
import { GroupType, consumeValue, getInvertedValues, getValues } from "@vitruvius-labs/testing-ground";
import { type Int32, NoValue, int32 } from "../../../../../src/_index.mjs";
import { IntegerBoundaryEnum } from "../../../../../src/extended/integer/definition/enum/integer-boundary.enum.mjs";

describe("int32", (): void => {
it("should return the provided value when given an integer with the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT32_MIN,
IntegerBoundaryEnum.INT32_MIN + 1,
-1,
0,
1,
IntegerBoundaryEnum.INT32_MAX - 1,
IntegerBoundaryEnum.INT32_MAX,
];

for (const ITEM of VALUES)
{
let result: unknown = NoValue;

const WRAPPER = (): void => {
result = int32(ITEM);
};

doesNotThrow(WRAPPER);

strictEqual(result, ITEM);
}
});

it("should throw when given an integer outside the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT32_MIN - 1,
IntegerBoundaryEnum.INT32_MAX + 1,
];

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int32(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given a non-integer number", (): void => {
const VALUES: Array<unknown> = getValues(GroupType.REAL, GroupType.INFINITY);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int32(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given anything else", (): void => {
const VALUES: Array<unknown> = getInvertedValues(GroupType.NUMBER);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int32(ITEM);
};

throws(WRAPPER);
}
});

it("should narrow the type to an Int32", (): void => {
const WRAPPER = (): void =>
{
consumeValue<Int32>(int32(NoValue));
};

throws(WRAPPER);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { doesNotThrow, strictEqual, throws } from "node:assert";
import { describe, it } from "node:test";
import { GroupType, consumeValue, getInvertedValues, getValues } from "@vitruvius-labs/testing-ground";
import { type Int8, NoValue, int8 } from "../../../../../src/_index.mjs";
import { IntegerBoundaryEnum } from "../../../../../src/extended/integer/definition/enum/integer-boundary.enum.mjs";

describe("int8", (): void => {
it("should return the provided value when given an integer with the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT8_MIN,
IntegerBoundaryEnum.INT8_MIN + 1,
-1,
0,
1,
IntegerBoundaryEnum.INT8_MAX - 1,
IntegerBoundaryEnum.INT8_MAX,
];

for (const ITEM of VALUES)
{
let result: unknown = NoValue;

const WRAPPER = (): void => {
result = int8(ITEM);
};

doesNotThrow(WRAPPER);

strictEqual(result, ITEM);
}
});

it("should throw when given an integer outside the boundaries", (): void => {
const VALUES: Array<number> = [
IntegerBoundaryEnum.INT8_MIN - 1,
IntegerBoundaryEnum.INT8_MAX + 1,
];

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int8(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given a non-integer number", (): void => {
const VALUES: Array<unknown> = getValues(GroupType.REAL, GroupType.INFINITY);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int8(ITEM);
};

throws(WRAPPER);
}
});

it("should throw when given anything else", (): void => {
const VALUES: Array<unknown> = getInvertedValues(GroupType.NUMBER);

for (const ITEM of VALUES)
{
const WRAPPER = (): void => {
int8(ITEM);
};

throws(WRAPPER);
}
});

it("should narrow the type to an Int8", (): void => {
const WRAPPER = (): void =>
{
consumeValue<Int8>(int8(NoValue));
};

throws(WRAPPER);
});
});
Loading