Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@helios-lang/codec-utils

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helios-lang/codec-utils - npm Package Compare versions

Comparing version 0.1.33 to 0.1.34

2

package.json
{
"name": "@helios-lang/codec-utils",
"version": "0.1.33",
"version": "0.1.34",
"description": "Primitive manipulation functions commonly used in encoding and decoding algorithms",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -6,3 +6,9 @@ export { toBytes } from "./ByteArrayLike.js"

export { Base64, decodeBase64, encodeBase64, isValidBase64 } from "./base64.js"
export { compareBytes, equalsBytes, padBytes, prepadBytes } from "./ops.js"
export {
compareBytes,
dummyBytes,
equalsBytes,
padBytes,
prepadBytes
} from "./ops.js"

@@ -9,0 +15,0 @@ /**

@@ -0,2 +1,52 @@

import { encodeIntBE } from "../int/be.js"
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @param {boolean} shortestFirst defaults to false (strictly lexicographic comparison)
* @returns {-1 | 0 | 1} -1 if a < b, 0 if a == b, 1 if a > b
*/
export function compareBytes(a, b, shortestFirst = false) {
const na = a.length
const nb = b.length
if (shortestFirst && na != nb) {
return na < nb ? -1 : 1
}
for (let i = 0; i < Math.min(na, nb); i++) {
if (a[i] < b[i]) {
return -1
} else if (a[i] > b[i]) {
return 1
}
}
if (na != nb) {
return na < nb ? -1 : 1
} else {
return 0
}
}
/**
* Used to create dummy hashes for testing
* @param {number} n
* @param {number} seed
* @returns {number[]}
*/
export function dummyBytes(n, seed = 0) {
return padBytes(encodeIntBE(seed), n).slice(0, n)
}
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @returns {boolean}
*/
export function equalsBytes(a, b) {
return compareBytes(a, b) == 0
}
/**
* Pad by appending zeroes.

@@ -47,40 +97,1 @@ * If `n < nCurrent`, pad to next multiple of `n`.

}
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @param {boolean} shortestFirst defaults to false (strictly lexicographic comparison)
* @returns {-1 | 0 | 1} -1 if a < b, 0 if a == b, 1 if a > b
*/
export function compareBytes(a, b, shortestFirst = false) {
const na = a.length
const nb = b.length
if (shortestFirst && na != nb) {
return na < nb ? -1 : 1
}
for (let i = 0; i < Math.min(na, nb); i++) {
if (a[i] < b[i]) {
return -1
} else if (a[i] > b[i]) {
return 1
}
}
if (na != nb) {
return na < nb ? -1 : 1
} else {
return 0
}
}
/**
*
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @returns {boolean}
*/
export function equalsBytes(a, b) {
return compareBytes(a, b) == 0
}

@@ -7,3 +7,3 @@ export { toBytes } from "./ByteArrayLike.js";

export { Base64, decodeBase64, encodeBase64, isValidBase64 } from "./base64.js";
export { compareBytes, equalsBytes, padBytes, prepadBytes } from "./ops.js";
export { compareBytes, dummyBytes, equalsBytes, padBytes, prepadBytes } from "./ops.js";
//# sourceMappingURL=index.d.ts.map
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @param {boolean} shortestFirst defaults to false (strictly lexicographic comparison)
* @returns {-1 | 0 | 1} -1 if a < b, 0 if a == b, 1 if a > b
*/
export function compareBytes(a: number[] | Uint8Array, b: number[] | Uint8Array, shortestFirst?: boolean): -1 | 0 | 1;
/**
* Used to create dummy hashes for testing
* @param {number} n
* @param {number} seed
* @returns {number[]}
*/
export function dummyBytes(n: number, seed?: number): number[];
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @returns {boolean}
*/
export function equalsBytes(a: number[] | Uint8Array, b: number[] | Uint8Array): boolean;
/**
* Pad by appending zeroes.

@@ -15,16 +35,2 @@ * If `n < nCurrent`, pad to next multiple of `n`.

export function prepadBytes(bytes: number[], n: number): any[];
/**
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @param {boolean} shortestFirst defaults to false (strictly lexicographic comparison)
* @returns {-1 | 0 | 1} -1 if a < b, 0 if a == b, 1 if a > b
*/
export function compareBytes(a: number[] | Uint8Array, b: number[] | Uint8Array, shortestFirst?: boolean): -1 | 0 | 1;
/**
*
* @param {number[] | Uint8Array} a
* @param {number[] | Uint8Array} b
* @returns {boolean}
*/
export function equalsBytes(a: number[] | Uint8Array, b: number[] | Uint8Array): boolean;
//# sourceMappingURL=ops.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc