MCPcopy
hub / github.com/rvagg/through2 / objectTransformFromReadable

Function objectTransformFromReadable

test/test.js:216–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

214}
215
216export async function objectTransformFromReadable () {
217 const source = Readable.from([
218 { temp: -2.2, unit: 'F' },
219 { temp: -40, unit: 'F' },
220 { temp: 212, unit: 'F' },
221 { temp: 22, unit: 'C' }
222 ])
223 const conv = objectTransform(async (record) => {
224 if (record.unit === 'F') {
225 record = { temp: ((record.temp - 32) * 5) / 9, unit: 'C' }
226 }
227 return record
228 })
229 source.pipe(conv)
230 const out = await collectObjects(conv)
231 deepEq(out.map((r) => Math.round(r.temp)), [-19, -40, 100, 22])
232 ok(out.every((r) => r.unit === 'C'))
233}
234
235export async function transformerReusableFactory () {
236 const Th = transformer(function (chunk, _enc, cb) {

Callers

nothing calls this directly

Calls 4

objectTransformFunction · 0.90
collectObjectsFunction · 0.85
okFunction · 0.85
deepEqFunction · 0.70

Tested by

no test coverage detected