Skip to content

Commit

Permalink
Merge pull request #303 from StocksyUnited/main
Browse files Browse the repository at this point in the history
Adds BigInt parsing support
  • Loading branch information
steelbrain authored Feb 11, 2025
2 parents 162fa71 + 77f11a0 commit e7f0caf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/unserialize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line import/no-cycle
/* global BigInt */
import Parser from './parser'
import { isInteger, getClass, getIncompleteClass, __PHP_Incomplete_Class, invariant } from './helpers'

Expand Down Expand Up @@ -46,7 +47,11 @@ function unserializeItem(parser: Parser, scope: Record<string, any>, options: Op
}
if (type === 'int' || type === 'float') {
const value = parser.readUntil(';')
return type === 'int' ? parseInt(value, 10) : parseFloat(value)
let parsedValue: number | BigInt = type === 'int' ? parseInt(value, 10) : parseFloat(value)
if (parsedValue.toString() !== value) {
parsedValue = BigInt(value) as BigInt
}
return parsedValue
}
if (type === 'boolean') {
const value = parser.readAhead(1)
Expand Down

0 comments on commit e7f0caf

Please sign in to comment.