strfry-policies/src/io.ts

20 lines
508 B
TypeScript
Raw Normal View History

2023-03-24 19:36:11 +00:00
import { readLines } from './deps.ts';
import type { InputMessage, OutputMessage } from './types.ts';
2023-03-24 19:36:11 +00:00
/**
* Get the first line from stdin.
* Can only be read ONCE, or else it returns undefined.
*/
async function readStdin(): Promise<InputMessage> {
const { value } = await readLines(Deno.stdin).next();
return JSON.parse(value);
}
/** Writes the output message to stdout. */
function writeStdout(msg: OutputMessage): void {
console.log(JSON.stringify(msg));
}
export { readStdin, writeStdout };