+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?: { |
+23
-1
@@ -1,1 +0,23 @@ | ||
| import{assert as n}from"@samual/lib/assert";function fromBigInt(n){const t=[];for(;n>=0;){let r=Number(0x7Fn&n);n>>=7n,n--&&(r|=128),t.push(r)}return t}function toBigInt(t,r={$:0}){let o=0n,i=0n;for(;;){const e=t[r.$++];if(n(null!=e,"src/index.ts:28:29"),o+=(0x7Fn&BigInt(e))+(i&&1n)<<i,i+=7n,!(128&e))return o}}export{fromBigInt,toBigInt}; | ||
| import { assert } from "@samual/lib/assert" | ||
| function fromBigInt(integer) { | ||
| const result = [] | ||
| for (; integer >= 0n; ) { | ||
| let value = Number(0x7fn & integer) | ||
| integer >>= 7n | ||
| integer-- && (value |= 128) | ||
| result.push(value) | ||
| } | ||
| return result | ||
| } | ||
| function toBigInt(data, index = { $: 0 }) { | ||
| let result = 0n, | ||
| offset = 0n | ||
| for (;;) { | ||
| const byte = data[index.$++] | ||
| assert(null != byte, "src/index.ts:55:29") | ||
| result += ((0x7fn & BigInt(byte)) + (offset && 1n)) << offset | ||
| offset += 7n | ||
| if (!(128 & byte)) return result | ||
| } | ||
| } | ||
| export { fromBigInt, toBigInt } |
+38
-1
@@ -1,1 +0,38 @@ | ||
| {"name":"bleb","version":"0.0.1","description":"remember to update urls in this file","repository":{"type":"git","url":"https://github.com/samualtnorman/bleb"},"author":"Samual Norman","license":"MIT","bugs":{"url":"https://github.com/samualtnorman/bleb/issues"},"homepage":"https://github.com/samualtnorman/bleb#readme","dependencies":{"@samual/lib":"0.8.1"},"type":"module","engine":{"node":">=16"},"exports":{"./*":"./*.js","./*.js":"./*.js"}} | ||
| { | ||
| "name": "bleb", | ||
| "version": "0.0.2", | ||
| "description": "Better LEB128", | ||
| "repository": "github:samualtnorman/bleb", | ||
| "author": "Samual Norman", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/samualtnorman/bleb/issues" | ||
| }, | ||
| "homepage": "https://github.com/samualtnorman/bleb#readme", | ||
| "dependencies": { | ||
| "@samual/lib": "^0.13.0" | ||
| }, | ||
| "type": "module", | ||
| "exports": { | ||
| ".": "./index.js", | ||
| "./*": "./*.js", | ||
| "./*.js": "./*.js" | ||
| }, | ||
| "keywords": [ | ||
| "encoding", | ||
| "serialization", | ||
| "encoder", | ||
| "decoder", | ||
| "decoding", | ||
| "deserialization", | ||
| "encode", | ||
| "decode", | ||
| "integer", | ||
| "bigint", | ||
| "leb128", | ||
| "bleb" | ||
| ], | ||
| "engines": { | ||
| "node": "^18.20 || ^20.10 || >=22" | ||
| } | ||
| } |
+34
-8
| # Better LEB128 | ||
| bleb | ||
| [](https://github.com/samualtnorman/bleb/actions/workflows/build.yml) [](https://github.com/samualtnorman/bleb/actions/workflows/lint.yml) | ||
| | Range | bleb | LEB128 | | ||
| |-----------------|---------|---------| | ||
| | 0 - 127 | 1 byte | 1 byte | | ||
| | 128 - 16383 | 2 bytes | 2 bytes | | ||
| | 16384 - 16511 | 2 bytes | 3 bytes | | ||
| | 16512 - 2097151 | 3 bytes | 3 bytes | | ||
| | Range | bleb | LEB128 | | ||
| |-------------------|---------|---------| | ||
| | 0 - 127 | 1 byte | 1 byte | | ||
| | 128 - 16383 | 2 bytes | 2 bytes | | ||
| | 16384 - 16511 | 2 bytes | 3 bytes | | ||
| | 16512 - 2097151 | 3 bytes | 3 bytes | | ||
| | 2097152 - 2113663 | 3 bytes | 4 bytes | | ||
| | ... | | ||
| ## 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 } | ||
| ``` |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3506
32.85%35
775%1
-50%40
185.71%0
-100%1
Infinity%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated