hex-lite
Version:
isomorphic hex library in 256 bytes
3 lines (2 loc) • 911 B
JavaScript
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.hexLite={})}(this,function(t){function r(t){for(var r=new DataView(t.buffer),e=r.byteLength,n=e-e%4,f="",i=0;i<n;i+=4)f+=("00000000"+r.getUint32(i).toString(16)).slice(-8);for(;i<e;i++){var o=r.getUint8(i).toString(16);f+=o.length<2?"0"+o:o}return f}function e(t){if(t.length%2)throw new Error("invalid hex:"+t);for(var r=t.length,e=r-r%8,n=new Uint8Array(r/2),f=new DataView(n.buffer),i=0;i<e;i+=8)f.setUint32(i/8,parseInt(t.substr(i,8),16));for(;i<r;i+=2)f.setUint8(i/2,parseInt(t.substr(i,2),16));return n}function n(t){return r(new Uint8Array(t))}function f(t){return e(t).buffer}var i={fromUint8Array:r,toUint8Array:e,fromBuffer:n,toBuffer:f};t.fromUint8Array=r,t.toUint8Array=e,t.fromBuffer=n,t.toBuffer=f,t.default=i});
//# sourceMappingURL=hex-lite.umd.js.map