UNPKG

hex-lite

Version:

isomorphic hex library in 256 bytes

3 lines (2 loc) 762 B
function r(r){for(var t=new DataView(r.buffer),e=t.byteLength,n=e-e%4,f="",o=0;o<n;o+=4)f+=("00000000"+t.getUint32(o).toString(16)).slice(-8);for(;o<e;o++){var i=t.getUint8(o).toString(16);f+=i.length<2?"0"+i:i}return f}function t(r){if(r.length%2)throw new Error("invalid hex:"+r);for(var t=r.length,e=t-t%8,n=new Uint8Array(t/2),f=new DataView(n.buffer),o=0;o<e;o+=8)f.setUint32(o/8,parseInt(r.substr(o,8),16));for(;o<t;o+=2)f.setUint8(o/2,parseInt(r.substr(o,2),16));return n}function e(t){return r(new Uint8Array(t))}function n(r){return t(r).buffer}var f={fromUint8Array:r,toUint8Array:t,fromBuffer:e,toBuffer:n};exports.fromUint8Array=r,exports.toUint8Array=t,exports.fromBuffer=e,exports.toBuffer=n,exports.default=f; //# sourceMappingURL=hex-lite.js.map