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
3 changes: 3 additions & 0 deletions ark/type/__tests__/integration/allConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ configure({
"number.epoch": {
description: "configured"
},
"number.finite": {
description: "configured"
},
"number.safe": {
description: "configured"
},
Expand Down
16 changes: 16 additions & 0 deletions ark/type/__tests__/keywords/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ contextualize(() => {
attest(Safe(NaN).toString()).snap("must be a number (was NaN)")
})

it("finite", () => {
const Finite = type("number.finite")
attest(Finite(42)).snap(42)
attest(Finite(-3.14)).snap(-3.14)
attest(Finite(0)).snap(0)
attest(Finite.allows(Number.MAX_VALUE)).equals(true)
attest(Finite.allows(-Number.MAX_VALUE)).equals(true)
attest(Finite(Infinity).toString()).snap(
"must be a finite number (was Infinity)"
)
attest(Finite(-Infinity).toString()).snap(
"must be a finite number (was -Infinity)"
)
attest(Finite(NaN).toString()).snap("must be a number (was NaN)")
})

it("doesn't allow NaN by default", () => {
attest(type.number.allows(Number.NaN)).equals(false)
attest(type.number(Number.NaN).toString()).snap(
Expand Down
17 changes: 17 additions & 0 deletions ark/type/keywords/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,27 @@ export const integer = rootSchema({
divisor: 1
})

const finite = rootSchema({
domain: {
domain: "number",
numberAllowsNaN: false
},
min: {
rule: -Number.MAX_VALUE,
meta: "a finite number"
},
max: {
rule: Number.MAX_VALUE,
meta: "a finite number"
}
})

export const number: number.module = Scope.module(
{
root: intrinsic.number,
integer,
epoch,
finite,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allConfig.ts is a checked-in generated file that the testAllConfig integration test uses to verify every keyword has a "configured" description. It currently does not include "number.finite", so the test will fail.

Run the generator to update it:

pnpm tsx ark/type/__tests__/integration/generateAllConfig.ts

safe: rootSchema({
domain: {
domain: "number",
Expand All @@ -64,6 +80,7 @@ export declare namespace number {
export type $ = {
root: number
epoch: number
finite: number
integer: number
safe: number
NaN: number
Expand Down
Loading