How to use the typeon.jsonParse function in typeon

To help you get started, we’ve selected a few typeon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepsweet / foxr / src / json-protocol.ts View on Github external
transform (chunk, encoding, callback) {
      let pos = 0

      if (remainingLength === 0) {
        pos = chunk.indexOf(SEPARATOR_CODE)
        remainingLength = parseInt(chunk.slice(0, pos).toString(), 10)
        pos += 1
      }

      const remainingData = chunk.slice(pos, pos + remainingLength)
      currentBuffer = Buffer.concat([currentBuffer, remainingData])
      remainingLength -= remainingData.length
      pos += remainingData.length

      if (remainingLength === 0) {
        this.push(jsonParse(currentBuffer.toString()))

        currentBuffer = Buffer.alloc(0)
      }

      if (pos < chunk.length) {
        return this._transform(chunk.slice(pos), encoding, callback)
      }

      callback()
    }
  })

typeon

Typed JSON parse and stringify for TypeScript

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis

Popular typeon functions