@danidoble/webserial-vending-commands
Version:
WebSerial Vending Commands
34 lines (33 loc) • 829 B
JavaScript
const i = (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");
}, s = ({
data: r,
removeAppend: n = !1,
appended: e = `
`
}) => {
const t = new TextDecoder("utf-8").decode(r);
return n ? t.replace(new RegExp(e, "g"), "") : t;
}, f = ({
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")), c = (r) => {
const n = new Uint8Array(r.length);
for (let e = 0; e < r.length; e++)
n[e] = parseInt(r[e], 16);
return n;
};
export {
f as U,
s as a,
c as h,
i as p
};