uint8-util
Advanced tools
Comparing version 2.1.7 to 2.1.8
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", |
12
util.js
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
33
0
9173
6
185
1