@iov/encoding
Advanced tools
Comparing version 1.2.0 to 2.0.0-alpha.0
@@ -16,2 +16,8 @@ "use strict"; | ||
class Decimal { | ||
constructor(atomics, fractionalDigits) { | ||
this.data = { | ||
atomics: new bn_js_1.default(atomics), | ||
fractionalDigits: fractionalDigits, | ||
}; | ||
} | ||
static fromUserInput(input, fractionalDigits) { | ||
@@ -72,8 +78,2 @@ Decimal.verifyFractionalDigits(fractionalDigits); | ||
} | ||
constructor(atomics, fractionalDigits) { | ||
this.data = { | ||
atomics: new bn_js_1.default(atomics), | ||
fractionalDigits: fractionalDigits, | ||
}; | ||
} | ||
toString() { | ||
@@ -80,0 +80,0 @@ const factor = new bn_js_1.default(10).pow(new bn_js_1.default(this.data.fractionalDigits)); |
@@ -10,2 +10,14 @@ "use strict"; | ||
class Uint32 { | ||
constructor(input) { | ||
if (Number.isNaN(input)) { | ||
throw new Error("Input is not a number"); | ||
} | ||
if (!Number.isInteger(input)) { | ||
throw new Error("Input is not an integer"); | ||
} | ||
if (input < 0 || input > 4294967295) { | ||
throw new Error("Input not in uint32 range: " + input.toString()); | ||
} | ||
this.data = input; | ||
} | ||
static fromBigEndianBytes(bytes) { | ||
@@ -25,14 +37,2 @@ if (bytes.length !== 4) { | ||
} | ||
constructor(input) { | ||
if (Number.isNaN(input)) { | ||
throw new Error("Input is not a number"); | ||
} | ||
if (!Number.isInteger(input)) { | ||
throw new Error("Input is not an integer"); | ||
} | ||
if (input < 0 || input > 4294967295) { | ||
throw new Error("Input not in uint32 range: " + input.toString()); | ||
} | ||
this.data = input; | ||
} | ||
toBytesBigEndian() { | ||
@@ -67,8 +67,2 @@ // Use division instead of shifting since bitwise operators are defined | ||
class Int53 { | ||
static fromString(str) { | ||
if (!str.match(/^-?[0-9]+$/)) { | ||
throw new Error("Invalid string format"); | ||
} | ||
return new Int53(Number.parseInt(str, 10)); | ||
} | ||
constructor(input) { | ||
@@ -86,2 +80,8 @@ if (Number.isNaN(input)) { | ||
} | ||
static fromString(str) { | ||
if (!str.match(/^-?[0-9]+$/)) { | ||
throw new Error("Invalid string format"); | ||
} | ||
return new Int53(Number.parseInt(str, 10)); | ||
} | ||
toNumber() { | ||
@@ -96,6 +96,2 @@ return this.data; | ||
class Uint53 { | ||
static fromString(str) { | ||
const signed = Int53.fromString(str); | ||
return new Uint53(signed.toNumber()); | ||
} | ||
constructor(input) { | ||
@@ -108,2 +104,6 @@ const signed = new Int53(input); | ||
} | ||
static fromString(str) { | ||
const signed = Int53.fromString(str); | ||
return new Uint53(signed.toNumber()); | ||
} | ||
toNumber() { | ||
@@ -118,2 +118,11 @@ return this.data.toNumber(); | ||
class Uint64 { | ||
constructor(data) { | ||
if (data.isNeg()) { | ||
throw new Error("Input is negative"); | ||
} | ||
if (data.gt(uint64MaxValue)) { | ||
throw new Error("Input exceeds uint64 range"); | ||
} | ||
this.data = data; | ||
} | ||
static fromBytesBigEndian(bytes) { | ||
@@ -156,11 +165,2 @@ if (bytes.length !== 8) { | ||
} | ||
constructor(data) { | ||
if (data.isNeg()) { | ||
throw new Error("Input is negative"); | ||
} | ||
if (data.gt(uint64MaxValue)) { | ||
throw new Error("Input exceeds uint64 range"); | ||
} | ||
this.data = data; | ||
} | ||
toBytesBigEndian() { | ||
@@ -167,0 +167,0 @@ return this.data.toArrayLike(Uint8Array, "be", 8); |
{ | ||
"name": "@iov/encoding", | ||
"version": "1.2.0", | ||
"version": "2.0.0-alpha.0", | ||
"description": "Encoding helpers for IOV projects", | ||
@@ -33,3 +33,3 @@ "author": "IOV SAS <admin@iov.one>", | ||
"test": "yarn build-or-skip && yarn test-node", | ||
"move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && shx rm ./types/*.spec.d.ts", | ||
"move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm ./types/*.spec.d.ts", | ||
"format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", | ||
@@ -49,3 +49,3 @@ "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", | ||
}, | ||
"gitHead": "3d3c018043d6d438ed9222bef413ecc52fbda1a7" | ||
"gitHead": "6a8923c2ee67f4190fba61952ca4e198e1e50d59" | ||
} |
@@ -10,4 +10,4 @@ /** | ||
private static verifyFractionalDigits; | ||
readonly atomics: string; | ||
readonly fractionalDigits: number; | ||
get atomics(): string; | ||
get fractionalDigits(): number; | ||
private readonly data; | ||
@@ -14,0 +14,0 @@ private constructor(); |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
61821
2