@harmoniclabs/cbor
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -12,2 +12,6 @@ import type { CborObj } from "../CborObj/index.js"; | ||
static parse(cbor: CborString | Uint8Array | string): CborObj; | ||
static parseWithOffset(cbor: CborString | Uint8Array | string): { | ||
parsed: CborObj; | ||
offset: number; | ||
}; | ||
} |
@@ -219,5 +219,8 @@ "use strict"; | ||
Cbor.parse = function (cbor) { | ||
return Cbor.parseWithOffset(cbor).parsed; | ||
}; | ||
Cbor.parseWithOffset = function (cbor) { | ||
if (typeof cbor === "string") | ||
cbor = (0, uint8array_utils_1.fromHex)(cbor); | ||
(0, assert_1.assert)((0, uint8array_utils_1.isUint8Array)(cbor) || CborString_1.CborString.isStrictInstance(cbor), "in 'Cbor.parse' expected an instance of 'CborString' or a 'Uint8Array' as input; got: " + cbor); | ||
(0, assert_1.assert)((cbor instanceof Uint8Array) || CborString_1.CborString.isStrictInstance(cbor), "in 'Cbor.parse' expected an instance of 'CborString' or a 'Uint8Array' as input; got: " + cbor); | ||
var bytes = cbor instanceof CborString_1.CborString ? | ||
@@ -312,3 +315,3 @@ cbor.toBuffer() : | ||
var headerByte = Number(getUInt8().num); | ||
if (headerByte === 0xff) // breack indefinite | ||
if (headerByte === 0xff) // break indefinite | ||
return BigInt(-1); | ||
@@ -413,9 +416,9 @@ var elemLength = getLength(headerByte & 31); | ||
if (nLen === 20) | ||
return new CborSimple_1.CborSimple(false); // f4 | ||
return new CborSimple_1.CborSimple(false); // 0xf4 | ||
if (nLen === 21) | ||
return new CborSimple_1.CborSimple(true); // f5 | ||
return new CborSimple_1.CborSimple(true); // 0xf5 | ||
if (nLen === 22) | ||
return new CborSimple_1.CborSimple(null); // f6 | ||
return new CborSimple_1.CborSimple(null); // 0xf6 | ||
if (nLen === 23) | ||
return new CborSimple_1.CborSimple(undefined); // f7 | ||
return new CborSimple_1.CborSimple(undefined); // 0xf7 | ||
// flaots handled at the beginning of the function | ||
@@ -428,3 +431,3 @@ // since length isn't required | ||
} | ||
return parseCborObj(); | ||
return { parsed: parseCborObj(), offset: offset }; | ||
}; | ||
@@ -431,0 +434,0 @@ return Cbor; |
@@ -64,3 +64,12 @@ "use strict"; | ||
var _a = __read(n.toString().split("."), 2), a = _a[0], b = _a[1]; | ||
return new CborPositiveRational(Number(a + b), Number("1e".concat(b.length))); | ||
/** | ||
* b might be undefinded (eg. whole numbers) | ||
* @since patch 1.1.2 | ||
**/ | ||
if (!(typeof b === "string")) { | ||
return new CborPositiveRational(Number(a), 1); | ||
} | ||
return new CborPositiveRational( | ||
// `a + b` is string concatenation | ||
Number(a + b), Number("1e".concat(b.length))); | ||
}; | ||
@@ -67,0 +76,0 @@ CborPositiveRational.prototype.toNumber = function () { |
{ | ||
"name": "@harmoniclabs/cbor", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "cbor library for easy cbor parsing, manipulation and conversion", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
79473
1942