JSPM

safe-integer-ts

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33498F
  • License CC0-1.0

Newtype wrapper of number type as safe-integer (53-bit precise integer)

Package Exports

  • safe-integer-ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (safe-integer-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SafeInteger for TypeScript

Provides SafeInteger type, a newtype wrapper of number as safe-integer or 53-bit precise integer.

See the implementations for more details.

Example

import { SafeInteger, asSafeInteger, isSafeInteger, toSafeInteger } from "safe-integer-ts"

const unknownValue: unknown = JSON.parse("42")

// As argument.
const useSafeInteger = (_value: SafeInteger) => {
    // No need to validate in case of non-integer, NaN, integer-like string, etc.
}

// Validate.
{
    if (isSafeInteger(unknownValue)) {
        useSafeInteger(unknownValue)
    }
}

// Cast.
{
    const value: SafeInteger | null = asSafeInteger(unknownValue)
    if (value != null) {
        useSafeInteger(value)
    }
}

// Convert.
{
    const value: SafeInteger | null = toSafeInteger("42")
    if (value != null) {
        useSafeInteger(value)
    }
}

ES module

import ... from "safe-integer-ts/esm"
//                              ^^^^