UNPKG

@onekeyfe/blockchain-libs

Version:
45 lines 1.5 kB
"use strict"; /* Copyright (c) 2019 Algorand, llc */ Object.defineProperty(exports, "__esModule", { value: true }); exports.removeUndefinedProperties = exports.concatArrays = exports.arrayEqual = void 0; /** * ArrayEqual takes two arrays and return true if equal, false otherwise */ function arrayEqual(a, b) { if (a.length !== b.length) { return false; } return Array.from(a).every((val, i) => val === b[i]); } exports.arrayEqual = arrayEqual; /** * ConcatArrays takes n number arrays and returns a joint Uint8Array * @param arrs - An arbitrary number of n array-like number list arguments * @returns [a,b] */ function concatArrays(...arrs) { const size = arrs.reduce((sum, arr) => sum + arr.length, 0); const c = new Uint8Array(size); let offset = 0; for (let i = 0; i < arrs.length; i++) { c.set(arrs[i], offset); offset += arrs[i].length; } return c; } exports.concatArrays = concatArrays; /** * Remove undefined properties from an object * @param obj - An object, preferably one with some undefined properties * @returns A copy of the object with undefined properties removed */ function removeUndefinedProperties(obj) { const mutableCopy = { ...obj }; Object.keys(mutableCopy).forEach((key) => { if (typeof mutableCopy[key] === 'undefined') delete mutableCopy[key]; }); return mutableCopy; } exports.removeUndefinedProperties = removeUndefinedProperties; //# sourceMappingURL=utils.js.map