mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
- Extract the checker-proven source arm before constructing a Buffer from a callback value. - Cover narrowed byte and number array callbacks with Node differential fixtures.
25 lines
792 B
TypeScript
25 lines
792 B
TypeScript
type SqlParam = string | number | boolean | null | Uint8Array;
|
|
|
|
function encodeParam(param: SqlParam): string | number | boolean | null | { $hex: string } {
|
|
if (param !== null && typeof param === "object") {
|
|
return { $hex: Buffer.from(param).toString("hex") };
|
|
}
|
|
return param;
|
|
}
|
|
|
|
function encodeParams(params: SqlParam[]): string {
|
|
return JSON.stringify(params.map(encodeParam));
|
|
}
|
|
|
|
console.log(encodeParams(["a", 1, true, null, new Uint8Array([0xde, 0xad])]));
|
|
|
|
type ListParam = string | number[] | null;
|
|
|
|
function encodeList(param: ListParam): string {
|
|
if (Array.isArray(param)) return Buffer.from(param).toString("hex");
|
|
return param === null ? "null" : param;
|
|
}
|
|
|
|
const listParams: ListParam[] = [null, [1, 254], "text"];
|
|
console.log(listParams.map(encodeList).join("|"));
|