mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 19:30:38 +08:00
Remove unused polyfills
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
"use strict";
|
||||
|
||||
import { Buffer } from "buffer/";
|
||||
import typedarrayToBuffer from "typedarray-to-buffer";
|
||||
|
||||
const ENC_UTF8 = "utf8";
|
||||
const ENC_HEX = "hex";
|
||||
const STRING_ZERO = "0";
|
||||
|
||||
export function bufferToArray(buf) {
|
||||
return new Uint8Array(buf);
|
||||
}
|
||||
|
||||
export function bufferToUtf8(buf) {
|
||||
return buf.toString(ENC_UTF8);
|
||||
}
|
||||
|
||||
export function bufferToHex(buf, prefixed = false) {
|
||||
const hex = buf.toString(ENC_HEX);
|
||||
return prefixed ? addHexPrefix(hex) : hex;
|
||||
}
|
||||
|
||||
export function utf8ToBuffer(utf8) {
|
||||
return Buffer.from(utf8, ENC_UTF8);
|
||||
}
|
||||
|
||||
export function utf8ToArray(utf8) {
|
||||
return bufferToArray(utf8ToBuffer(utf8));
|
||||
}
|
||||
|
||||
export function hexToArray(hex) {
|
||||
return bufferToArray(hexToBuffer(hex));
|
||||
}
|
||||
|
||||
export function hexToBuffer(hex) {
|
||||
return Buffer.from(removeHexPrefix(hex), ENC_HEX);
|
||||
}
|
||||
|
||||
export function removeHexPrefix(hex) {
|
||||
return hex.replace(/^0x/, "");
|
||||
}
|
||||
|
||||
export function addHexPrefix(hex) {
|
||||
return hex.startsWith("0x") ? hex : `0x${hex}`;
|
||||
}
|
||||
|
||||
export function arrayToBuffer(arr) {
|
||||
return typedarrayToBuffer(arr);
|
||||
}
|
||||
|
||||
export function arrayToHex(arr, prefixed = false) {
|
||||
return bufferToHex(arrayToBuffer(arr), prefixed);
|
||||
}
|
||||
|
||||
export function arrayToUtf8(arr) {
|
||||
return bufferToUtf8(arrayToBuffer(arr));
|
||||
}
|
||||
|
||||
export function sanitizeHex(hex) {
|
||||
hex = removeHexPrefix(hex);
|
||||
hex = sanitizeBytes(hex, 2);
|
||||
if (hex) {
|
||||
hex = addHexPrefix(hex);
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
export function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
|
||||
return padLeft(str, calcByteLength(str.length, byteSize), padding);
|
||||
}
|
||||
|
||||
export function padLeft(str, length, padding = STRING_ZERO) {
|
||||
return padString(str, length, true, padding);
|
||||
}
|
||||
|
||||
export function calcByteLength(length, byteSize = 8) {
|
||||
const remainder = length % byteSize;
|
||||
return remainder
|
||||
? ((length - remainder) / byteSize) * byteSize + byteSize
|
||||
: length;
|
||||
}
|
||||
|
||||
export function concatArrays(...args) {
|
||||
let result = [];
|
||||
args.forEach(arg => (result = result.concat(Array.from(arg))));
|
||||
return new Uint8Array([...result]);
|
||||
}
|
||||
|
||||
export function padString(str, length, left, padding = STRING_ZERO) {
|
||||
const diff = length - str.length;
|
||||
let result = str;
|
||||
if (diff > 0) {
|
||||
const pad = padding.repeat(diff);
|
||||
result = left ? pad + str : str + pad;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import isTypedArray from "is-typedarray";
|
||||
import { Buffer } from "buffer/";
|
||||
|
||||
export default function typedarrayToBuffer(arr) {
|
||||
if (isTypedArray.strict(arr)) {
|
||||
let buf = Buffer.from(arr.buffer);
|
||||
if (arr.byteLength !== arr.buffer.byteLength) {
|
||||
buf = buf.slice(arr.byteOffset, arr.byteOffset + arr.byteLength);
|
||||
}
|
||||
return buf;
|
||||
} else {
|
||||
return Buffer.from(arr);
|
||||
}
|
||||
}
|
||||
@@ -36,12 +36,6 @@ const config: UserConfig = {
|
||||
alias: {
|
||||
"@public": path.resolve("./public"),
|
||||
"@app": path.resolve("./src"),
|
||||
"typedarray-to-buffer": path.resolve(
|
||||
"./src/polyfills/typedarray-to-buffer.js",
|
||||
),
|
||||
// "Buffer" is not defined in the published package..
|
||||
"@walletconnect/encoding": path.resolve("./src/polyfills/enc-utils.js"),
|
||||
"enc-utils": path.resolve("./src/polyfills/enc-utils.js"),
|
||||
},
|
||||
},
|
||||
define: {
|
||||
|
||||
Reference in New Issue
Block a user