Socket
Socket
Sign inDemoInstall

uint8-util

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uint8-util - npm Package Compare versions

Comparing version 2.1.9 to 2.2.1

12

browser.js

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

import { arr2hex, alphabet } from './util.js'
import { arr2hex, hex2arr, alphabet } from './util.js'
import { decode, encode } from 'base64-arraybuffer'

@@ -28,4 +28,3 @@

c = str.charCodeAt(i++)
res += alphabet[c >> 4]
res += alphabet[c & 0xF]
res += alphabet[c >> 4] + alphabet[c & 0xF]
}

@@ -38,6 +37,3 @@

export const hex2bin = hex => {
const points = new Array(hex.length / 2)
for (let i = 0, l = hex.length / 2; i < l; ++i) {
points[i] = parseInt(hex.substr(i * 2, 2), 16)
}
const points = hex2arr(hex)
if (points.length <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode(...points)

@@ -48,3 +44,3 @@

while (i < points.length) {
res += String.fromCharCode(...points.slice(i, i += MAX_ARGUMENTS_LENGTH))
res += String.fromCharCode(...points.subarray(i, i += MAX_ARGUMENTS_LENGTH))
}

@@ -51,0 +47,0 @@ return res

@@ -30,3 +30,5 @@ type TypedArray =

type HexPrimitive = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
type Uint8 = Uint8Array | Array
type HexPrimitive = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
type HexPart<S extends string | number> = `${S}${'' | `${S}`}`

@@ -40,13 +42,13 @@ type Hex = HexPart<HexPart<HexPrimitive>>

export function concat (chunks: (TypedArray | Array)[]): Uint8Array
export function concat (chunks: (TypedArray | Array)[], size?: number): Uint8Array
export function equal (a: TypedArray, b: TypedArray): boolean
export function equal (a: Uint8, b: Uint8): boolean
export function arr2hex (data: Uint8Array | Array): Hex
export function arr2hex (data: Uint8): Hex
export function hex2array (str: Hex): Uint8Array
export function arr2text (data: ArrayBuffer | Uint8Array, enc: Encoding): string
export function arr2text (data: ArrayBuffer | Uint8Array, enc?: Encoding): string
export function arr2base (data: Uint8Array | Array): Base64
export function arr2base (data: Uint8): Base64

@@ -61,4 +63,4 @@ export function base2arr (str: Base64): Uint8Array

export async function hash (data: string | TypedArray | ArrayBuffer | DataView, format: HashType, algo: HashAlgo): Uint8Array | Hex | Base64
export async function hash (data: string | TypedArray | ArrayBuffer | DataView, format?: HashType, algo?: HashAlgo): Promise<Uint8Array | Hex | Base64>
export function randomBytes (size: number): Uint8Array
{
"name": "uint8-util",
"version": "2.1.9",
"version": "2.2.1",
"description": "Fastest possible buffer-like utilities for uint8.",

@@ -57,2 +57,4 @@ "main": "index.js",

"bench-node-2arr": "node benchmark/text2arr.js",
"bench-node-hex2arr": "node benchmark/hex2arr.js",
"bench-browser-hex2arr": "airtap --preset local -- benchmark/hex2arr.js",
"bench-browser-bin2hex": "airtap --preset local -- benchmark/bin2hex.js",

@@ -59,0 +61,0 @@ "bench-browser-hex2bin": "airtap --preset local -- benchmark/hex2bin.js",

@@ -43,6 +43,6 @@ /* Common package for dealing with hex/string/uint8 conversions (and sha1 hashing)

export const concat = (chunks, size) => {
export const concat = (chunks, size = 0) => {
const length = chunks.length || 0
if (!size) {
size = 0
let i = chunks.length || chunks.byteLength || 0
let i = length
while (i--) size += chunks[i].length

@@ -52,5 +52,6 @@ }

let offset = 0
for (const chunk of chunks) {
b.set(chunk, offset)
offset += chunk.byteLength || chunk.length
let i = length
while (i--) {
b.set(chunks[i], offset)
offset += chunks[i].length
}

@@ -62,3 +63,3 @@

export const equal = (a, b) => {
if (a.byteLength !== b.byteLength) return false
if (a.length !== b.length) return false
for (let i = a.length; i > -1; i -= 1) {

@@ -65,0 +66,0 @@ if ((a[i] !== b[i])) return false

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