gsantiago/subtitle.js

View on GitHub
src/map.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Transform } from 'stream'
import { Node } from '.'

export const map = (mapper: (node: Node, index: number) => any) => {
  let index = 0

  return new Transform({
    objectMode: true,
    autoDestroy: false,
    transform(chunk: Node, _encoding, callback) {
      callback(null, mapper(chunk, index++))
    }
  })
}