dreambase-library
Advanced tools
Comparing version 1.0.7 to 1.0.8
import { TypeDefSet } from "../TypeDefSet.js"; | ||
export declare const MAXUINT64: number | bigint; | ||
declare const bigIntDef: TypeDefSet; | ||
export default bigIntDef; | ||
//# sourceMappingURL=bigint.d.ts.map |
import { b64ToBigInt, bigint2B64 } from "../../common/bigint-conversion.js"; | ||
export const MAXUINT64 = typeof BigInt !== "undefined" | ||
? BigInt("18446744073709551615") | ||
: 281474976710655; | ||
const bigIntDef = { | ||
bigint: { | ||
replace: (realVal) => { | ||
const negative = realVal < 0; | ||
const b64 = bigint2B64(negative ? -realVal : realVal); | ||
return negative | ||
? { | ||
if (realVal <= MAXUINT64) { | ||
// Negative and realtively small numbers - represent as normal numbers | ||
return { $t: "bigint", v: "" + realVal }; | ||
} | ||
else { | ||
// Very large positive numbers - compress to base64 | ||
const b64 = bigint2B64(realVal); | ||
return { | ||
$t: "bigint", | ||
neg: true, | ||
b64, | ||
} | ||
: { | ||
$t: "bigint", | ||
b64, | ||
}; | ||
} | ||
}, | ||
revive: ({ neg, b64 }) => neg ? -b64ToBigInt(b64) : b64ToBigInt(b64), | ||
revive: (obj) => ("v" in obj ? BigInt(obj.v) : b64ToBigInt(obj.b64)), | ||
}, | ||
}; | ||
export default bigIntDef; |
@@ -82,6 +82,2 @@ const { toString: toStr } = {}; | ||
switch (typeof realVal) { | ||
case "string": | ||
case "boolean": | ||
case "undefined": | ||
return typeDefs[type]; | ||
case "number": | ||
@@ -91,4 +87,2 @@ return isNaN(realVal) || realVal === Infinity || realVal === -Infinity | ||
: typeDefs.NormalNumber; | ||
case "bigint": | ||
return typeDefs.bigint; | ||
case "object": | ||
@@ -119,6 +113,6 @@ case "function": { | ||
} | ||
case "symbol": | ||
return typeDefs.symbol; | ||
default: | ||
return typeDefs[type]; | ||
} | ||
} | ||
} |
{ | ||
"name": "dreambase-library", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Library of dreambase-related code for use in other libraries.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42969
973