How to use typeon - 2 common examples

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()
    }
  })
github deepsweet / foxr / src / json-protocol.ts View on Github external
export const stringify = (data: TJsonValue) => {
  const str = jsonStringify(data)
  const length = Buffer.byteLength(str)

  return `${length}${SEPARATOR}${str}`
}

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