Skip to content

Commit

Permalink
Revision 0.32.26 (#851)
Browse files Browse the repository at this point in the history
* Use Optimized Number Check

* Fix Readme Error | Update Overview

* Version
  • Loading branch information
sinclairzx81 committed Apr 27, 2024
1 parent 1ba927c commit a670487
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.32.25",
"version": "0.32.26",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Expand Up @@ -53,7 +53,7 @@ type T = Static<typeof T> // type T = {
TypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.
This library is designed to allow Json Schema to compose with the same flexibility as TypeScript's programmable type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
This library is designed to allow Json Schema to compose with a similar flexibility to TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.
License MIT
Expand Down Expand Up @@ -895,9 +895,9 @@ const K = Type.TemplateLiteral('prop${A|B|C}') // const K: TTemplateLitera
// ]>

const R = Type.Record(K, Type.String()) // const R: TObject<{
// hello1: TString,
// hello2: TString,
// hello3: TString,
// propA: TString,
// propB: TString,
// propC: TString,
// }>
```
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compiler.ts
Expand Up @@ -210,7 +210,7 @@ export namespace Policy {
: `(typeof ${value} === 'object' && ${value} !== null && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))`
}
export function IsNumberLike(value: string): string {
return !TypeSystemPolicy.AllowNaN ? `(typeof ${value} === 'number' && Number.isFinite(${value}))` : `typeof ${value} === 'number'`
return TypeSystemPolicy.AllowNaN ? `typeof ${value} === 'number'` : `Number.isFinite(${value})`
}
export function IsVoidLike(value: string): string {
return TypeSystemPolicy.AllowNullVoid ? `(${value} === undefined || ${value} === null)` : `${value} === undefined`
Expand Down Expand Up @@ -288,7 +288,7 @@ export namespace TypeCompiler {
yield `(typeof ${value} === 'function')`
}
function* FromInteger(schema: TInteger, references: TSchema[], value: string): IterableIterator<string> {
yield `(typeof ${value} === 'number' && Number.isInteger(${value}))`
yield `Number.isInteger(${value})`
if (IsNumber(schema.exclusiveMaximum)) yield `${value} < ${schema.exclusiveMaximum}`
if (IsNumber(schema.exclusiveMinimum)) yield `${value} > ${schema.exclusiveMinimum}`
if (IsNumber(schema.maximum)) yield `${value} <= ${schema.maximum}`
Expand Down
3 changes: 1 addition & 2 deletions src/system/policy.ts
Expand Up @@ -56,8 +56,7 @@ export namespace TypeSystemPolicy {
}
/** Asserts this value using the AllowNaN policy */
export function IsNumberLike(value: unknown): value is number {
const isNumber = IsNumber(value)
return AllowNaN ? isNumber : isNumber && Number.isFinite(value)
return AllowNaN ? IsNumber(value) : Number.isFinite(value)
}
/** Asserts this value using the AllowVoidNull policy */
export function IsVoidLike(value: unknown): value is void {
Expand Down
2 changes: 1 addition & 1 deletion src/type/guard/type.ts
Expand Up @@ -30,7 +30,7 @@ import * as ValueGuard from './value'
import { Kind, Hint, TransformKind, ReadonlyKind, OptionalKind } from '../symbols/index'
import { TypeBoxError } from '../error/index'
import { TransformOptions } from '../transform/index'
import { TTemplateLiteral, TTemplateLiteralKind } from '../template-literal/index'
import { TTemplateLiteral } from '../template-literal/index'
import { TArray } from '../array/index'
import { TBoolean } from '../boolean/index'
import type { TRecord } from '../record/index'
Expand Down
2 changes: 1 addition & 1 deletion src/value/guard/guard.ts
Expand Up @@ -171,7 +171,7 @@ export function IsNumber(value: unknown): value is number {
}
/** Returns true if this value is an integer */
export function IsInteger(value: unknown): value is number {
return IsNumber(value) && Number.isInteger(value)
return Number.isInteger(value)
}
/** Returns true if this value is bigint */
export function IsBigInt(value: unknown): value is bigint {
Expand Down

0 comments on commit a670487

Please sign in to comment.