Open this example in the interactive library
Source code
import { Readable } from "node:stream";
import { createInterface } from "node:readline";
const input = Readable.from([
'{"key":"home","en":"Home","fr":"Accueil"}\n',
'{"key":"save","en":"Save","fr":"Enregistrer"}\n',
'{"key":"help","en":"Help","fr":""}\n',
]);
const rows = [];
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
rows.push(JSON.parse(line));
}
const result = rows
.filter((r) => r.fr.length > r.en.length)
.map((r) => ({ key: r.key, extra: r.fr.length - r.en.length }));
console.log(JSON.stringify(result, null, 2));
Sample output
[
{
"key": "home",
"extra": 3
},
{
"key": "save",
"extra": 7
}
]