UNPKG

@melonproject/token-math

Version:

A small helper library to do precision safe calculations

30 lines (29 loc) 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsbi_1 = __importDefault(require("jsbi")); /** * This is a super small helper class just to enable type safety * It stores its value as a string. * * This class is not intended to be enhanced or anything (since we are still strictly functional here) */ class BigInteger extends String { constructor(value) { const jsbi = jsbi_1.default.BigInt(value); super(jsbi.toString()); this.value = jsbi; if (typeof value === "number" && jsbi_1.default.greaterThan(jsbi, jsbi_1.default.BigInt(Number.MAX_SAFE_INTEGER))) { console.warn("Provided value as number bigger than Number.MAX_SAFE_INTEGER. Use strings or BigInt.", jsbi.toString()); } if (typeof value === "number" && jsbi_1.default.lessThan(jsbi, jsbi_1.default.BigInt(Number.MIN_SAFE_INTEGER))) { console.warn("Provided value as number less than Number.MIN_SAFE_INTEGER. Use strings or BigInt.", jsbi.toString()); } } } exports.BigInteger = BigInteger; exports.default = BigInteger;