Skip to content

Consider using Number.isSafeInteger(i) #80

Description

@dlongley
  • Does this need more edge case checks?
  • Might consider at least having a zero and negative int check. Probably Number.MIN/MAX_SAFE_INTEGER too.
  • Does this need the reverse checks of data with a plain int and query with an int string? I think the code would handle that?
  • Parsed JSON itself with native ints will (probably?) be limited to Number.MIN/MAX_SAFE_INTEGER. But if both sides had strings with non safe int values, I think this starts to lose precision and would cause matching failures. In any case, havoc will probably happen. Is that important to handle here?

Example:

> Number.MAX_SAFE_INTEGER
9007199254740991
> a = parseInt('9007199254740992')
9007199254740992
> b = parseInt('9007199254740993')
9007199254740992
> a.toString()
'9007199254740992'
> b.toString()
'9007199254740992'
> a.toString() === b.toString()
true
  • One solution might be to use BigInt(x), but that's introducing radix prefix issues and returning BigInts vs ints for comparison and no doubt has odd issues.
  • Another solution is to specifically not handle these issues and after the parseInt, check if Number.isSafeInteger(i) is false, then return x. Would need some tests to make sure that works and simply refuses to match those non-safe string values for now.

Originally posted by @davidlehn in #79 (review)


We probably only want the Number.isSafeInteger(i) check, not any BigInt checks. We're only interested, I think, in converting integers for array indexing processing and interoperable JSON numbers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions