UNPKG

@nucypher/shared

Version:

## [`nucypher/taco-web`](../../README.md)

23 lines 1.12 kB
import deepEqual from 'deep-equal'; // TODO: Replace byte and hex manipulation with ethers.js export const toBytes = (str) => new TextEncoder().encode(str); export const fromBytes = (bytes) => new TextDecoder().decode(bytes); export const fromHexString = (hexString) => { if (hexString.startsWith('0x')) { hexString = hexString.slice(2); } const matches = hexString.match(/.{1,2}/g) ?? []; return new Uint8Array(matches.map((byte) => parseInt(byte, 16))); }; export const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); export const toBase64 = (bytes) => btoa(String.fromCharCode(...bytes)); export const fromBase64 = (str) => Uint8Array.from(atob(str), (c) => c.charCodeAt(0)); export const zip = (a, b) => a.map((k, i) => [k, b[i]]); export const toEpoch = (date) => (date.getTime() / 1000) | 0; export const objectEquals = (a, b, strict = true) => deepEqual(a, b, { strict }); export const omit = (obj, keys) => { const copy = { ...obj }; keys.forEach((key) => delete copy[key]); return copy; }; //# sourceMappingURL=utils.js.map