Open this example in the interactive library
Source code
import { Readable } from "node:stream";
import { createInterface } from "node:readline";
const input = Readable.from([
'{"task":"design","needs":[]}\n',
'{"task":"build","needs":["design"]}\n',
'{"task":"test","needs":["build"]}\n',
'{"task":"ship","needs":["build","test"]}\n',
]);
const rows = [];
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
rows.push(JSON.parse(line));
}
const result = rows
.filter((r) => r.task !== "design")
.map((r) => ({ ...r, needs: r.needs.filter((n) => n !== "design") }));
console.log(JSON.stringify(result, null, 2));
Sample output
[
{
"task": "build",
"needs": []
},
{
"task": "test",
"needs": [
"build"
]
},
{
"task": "ship",
"needs": [
"build",
"test"
]
}
]