+8
-0
@@ -0,1 +1,9 @@ | ||
| /** | ||
| * @example Basic Usage | ||
| * ```ts | ||
| * import * as Bleb from "bleb" | ||
| * | ||
| * console.log(Bleb.fromBigInt(1000n)) // [ 232, 6 ] | ||
| * ``` | ||
| */ | ||
| export declare function fromBigInt(integer: bigint): number[]; | ||
@@ -2,0 +10,0 @@ export declare function toBigInt(data: Record<number, number>, index?: { |
+2
-2
| import { assert } from "@samual/lib/assert" | ||
| function fromBigInt(integer) { | ||
| const result = [] | ||
| for (; integer >= 0; ) { | ||
| for (; integer >= 0n; ) { | ||
| let value = Number(0x7fn & integer) | ||
@@ -17,3 +17,3 @@ integer >>= 7n | ||
| const byte = data[index.$++] | ||
| assert(null != byte, "src/index.ts:28:29") | ||
| assert(null != byte, "src/index.ts:55:29") | ||
| result += ((0x7fn & BigInt(byte)) + (offset && 1n)) << offset | ||
@@ -20,0 +20,0 @@ offset += 7n |
+1
-1
| { | ||
| "name": "bleb", | ||
| "version": "0.1.0-60dc504", | ||
| "version": "0.1.0-6e3403a", | ||
| "description": "Better LEB128", | ||
@@ -5,0 +5,0 @@ "repository": "github:samualtnorman/bleb", |
+28
-0
@@ -12,1 +12,29 @@ # Better LEB128 | ||
| | ... | | ||
| ## Encoding | ||
| ### Basic Usage | ||
| ```js | ||
| import * as Bleb from "bleb" | ||
| console.log(Bleb.fromBigInt(1000n)) // [ 232, 6 ] | ||
| ``` | ||
| ## Decoding | ||
| ### Basic Usage | ||
| ```js | ||
| import * as Bleb from "bleb" | ||
| console.log(Bleb.toBigInt([ 232, 6 ])) // 1000n | ||
| ``` | ||
| ### Less-Basic Usage | ||
| ```js | ||
| import * as Bleb from "bleb" | ||
| // some data with bleb at byte offset 2 | ||
| const u8View = new Uint8Array([ 177, 218, 232, 6, 197, 165, 75, 177 ]) | ||
| const index = { $: 2 } | ||
| console.log(Bleb.toBigInt(u8View, index)) // 1000n | ||
| console.log(index) // { $: 4 } | ||
| ``` |
3424
23.52%35
29.63%40
233.33%