Skip to content

Conversation

vanyauhalin
Copy link

Hi Eugene! I just wanted to say that your library is awesome.

I've a request. Would it be possible for you to add the makeObject option for the Stringers since we already have the makeArray one? I've a situation where I need to process an array of elements into a map.

Thanks in advance!

[
  { "id": "first" },
  // ...
  { "id": "fifth" }
]
{
  "first": 0,
  // ...
  "fifth": 4
}
let i = 0

new Chain([
  createReadStream(from),
  parser(),
  new StreamArray(),
  new Transform({
    objectMode: true,
    transform(ch, _, cb) {
      pushPair.call(this, ch.value.id, i)
      i += 1
      cb(null)
    }
  }),
  new Transform({
    objectMode: true,
    transform(ch, enc, cb) {
      this.push({ name: "startObject" })
      this._transform = transformPassThrough
      return this._transform(ch, enc, cb)
    },
    flush(cb) {
      if (this._transform === transformPassThrough) {
        this.push({ name: "endObject" })
      }
      cb(null)
    }
  }),
  new Stringer(),
  createWriteStream(to)
])

function transformPassThrough(ch, enc, cb) {
  this.push(ch, enc)
  cb(null)
}

@uhop uhop self-assigned this Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants