@danidoble/webserial-vending-commands
Version:
WebSerial Vending Commands
3 lines (2 loc) • 744 B
JavaScript
;const o=r=>{if(r instanceof Uint8Array)return r;if(Array.isArray(r))return new Uint8Array(r);if(typeof r=="string")return new TextEncoder().encode(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);throw new Error("Unsupported data type")},i=({data:r,removeAppend:n=!1,appended:e=`
`})=>{const t=new TextDecoder("utf-8").decode(r);return n?t.replace(new RegExp(e,"g"),""):t},s=({data:r,asString:n=!0})=>n?Array.from(r).map(e=>e.toString(16).padStart(2,"0")).join(" "):Array.from(r).map(e=>e.toString(16).padStart(2,"0")),f=r=>{const n=new Uint8Array(r.length);for(let e=0;e<r.length;e++)n[e]=parseInt(r[e],16);return n};exports.Uint8ArrayToHex=s;exports.Uint8ArrayToString=i;exports.hexToUint8Array=f;exports.parseToBuffer=o;