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

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.7 to 2.1.8

index.d.ts

14

_node.js
import { createHash, randomBytes as rand } from 'node:crypto'
const decoder = new TextDecoder()
export const arr2text = buffer => {
if (buffer.byteLength > 1024) return decoder.decode(buffer)
return Buffer.from(buffer).toString('utf8')
export const arr2text = (data, enc) => {
if (data.byteLength > 1024) {
if (!enc) return decoder.decode(data)
const dec = new TextDecoder(enc)
return dec.decode(data)
}
return Buffer.from(data).toString(enc || 'utf8')
}
export const text2arr = str => new Uint8Array(Buffer.from(str, 'utf-8'))
export const text2arr = str => new Uint8Array(Buffer.from(str, 'utf8'))
export const arr2base = buffer => Buffer.from(buffer).toString('base64')
export const arr2base = data => Buffer.from(data).toString('base64')

@@ -13,0 +17,0 @@ export const base2arr = str => new Uint8Array(Buffer.from(str, 'base64'))

@@ -6,9 +6,13 @@ import { arr2hex, alphabet } from './util.js'

// 50% slower at < 48 chars, but little impact at 4M OPS/s vs 8M OPS/s
export const arr2text = (buffer) => decoder.decode(buffer)
export const arr2text = (data, enc) => {
if (!enc) return decoder.decode(data)
const dec = new TextDecoder(enc)
return dec.decode(data)
}
// sacrifice ~20% speed for bundle size
const encoder = new TextEncoder()
export const text2arr = string => encoder.encode(string)
export const text2arr = str => encoder.encode(str)
export const arr2base = buffer => encode(buffer)
export const arr2base = data => encode(data)

@@ -15,0 +19,0 @@ export const base2arr = str => new Uint8Array(decode(str))

{
"name": "uint8-util",
"version": "2.1.7",
"version": "2.1.8",
"description": "Fastest possible buffer-like utilities for uint8.",

@@ -11,4 +11,6 @@ "main": "index.js",

"node": "./_node.js",
"default": "./browser.js"
"default": "./browser.js",
"import": "./browser.js"
},
"types": "./index.d.ts",
"repository": {

@@ -18,2 +20,8 @@ "type": "git",

},
"files": [
"_node.js",
"browser.js",
"util.js",
"index.d.ts"
],
"keywords": [

@@ -20,0 +28,0 @@ "uint8",

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

export const arr2hex = array => {
const length = array.length
export const arr2hex = data => {
const length = data.length
let string = ''
let i = 0
while (i < length) {
string += encodeLookup[array[i++]]
string += encodeLookup[data[i++]]
}

@@ -32,4 +32,4 @@ return string

export const hex2arr = string => {
const sizeof = string.length >> 1
export const hex2arr = str => {
const sizeof = str.length >> 1
const length = sizeof << 1

@@ -40,3 +40,3 @@ const array = new Uint8Array(sizeof)

while (i < length) {
array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)]
array[n++] = decodeLookup[str.charCodeAt(i++)] << 4 | decodeLookup[str.charCodeAt(i++)]
}

@@ -43,0 +43,0 @@ return array

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