Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.34.15 #1148

Merged
merged 3 commits into from
Jan 30, 2025
Merged
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: 2 additions & 0 deletions changelog/0.34.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 0.34.0
- [Revision 0.34.15](https://github.com/sinclairzx81/typebox/pull/1148)
- [1147](https://github.com/sinclairzx81/typebox/issues/1147) Fix incorrect truncation for integers that exceed 32-bit values in Value.Convert
- [Revision 0.34.14](https://github.com/sinclairzx81/typebox/pull/1140)
- [1139](https://github.com/sinclairzx81/typebox/issues/1139) Update TypeCompiler Check for Promise (use instanceof Promise over Thenable check)
- [Revision 0.34.13](https://github.com/sinclairzx81/typebox/pull/1124)
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.34.14",
"version": "0.34.15",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion src/value/convert/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function TryConvertNumber(value: unknown) {
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value
}
function TryConvertInteger(value: unknown) {
return IsStringNumeric(value) ? parseInt(value) : IsNumber(value) ? value | 0 : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value
return IsStringNumeric(value) ? parseInt(value) : IsNumber(value) ? Math.trunc(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value
}
function TryConvertNull(value: unknown) {
return IsString(value) && value.toLowerCase() === 'null' ? null : value
Expand Down
23 changes: 23 additions & 0 deletions test/runtime/value/convert/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,27 @@ describe('value/convert/Integer', () => {
const result = Value.Convert(Type.Integer(), value)
Assert.IsEqual(result, [])
})
// ----------------------------------------------------------
// https://github.com/sinclairzx81/typebox/issues/1147
// ----------------------------------------------------------
it('Should convert large Integer 1', () => {
const N = 1738213389080
const R = Value.Convert(Type.Integer(), N)
Assert.IsEqual(R, N)
})
it('Should convert large Integer 2', () => {
const N = 1738213389080.5555
const R = Value.Convert(Type.Integer(), N)
Assert.IsEqual(R, 1738213389080)
})
it('Should convert large Integer 3', () => {
const N = '1738213389080'
const R = Value.Convert(Type.Integer(), N)
Assert.IsEqual(R, 1738213389080)
})
it('Should convert large Integer 3', () => {
const N = '1738213389080.555'
const R = Value.Convert(Type.Integer(), N)
Assert.IsEqual(R, 1738213389080)
})
})