JSPM

pipe-segment-scope-codec

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q30183F
  • License MIT

Scope a pipe-segment-codec.

Package Exports

  • pipe-segment-scope-codec

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pipe-segment-scope-codec) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pipe-segment-scope-codec

Scope the work of a pipe-segment-codec, using scoped-transform-stream.

npm install pipe-segment-scope-codec

Example

var codec = require('pipe-segment-codec')
var scope = require('./')

var jsonc = codec(encode, decode)
function encode(data) {
  return JSON.stringify(data)
}

function decode(data) {
  return JSON.parse(data)
}

var scoped = scope(jsonc, '/msg')
scoped.decodeErrors.on('data', console.log)
scoped.encodeErrors.on('data', console.log)

scoped.encoded.on('data', console.log)
scoped.decoded.write({msg: {hello: "world"} }) // {msg: '{"hello":"world"}'}
scoped.decoded.write({msg: {beep: "boop"}, context: [] }) // {msg: '{"beep":"boop"}', context: [] }

scoped.decoded.on('data', console.log)
scoped.encoded.write({msg: '{"hello":"world"}' }) // {msg: {hello: "world"} }
scoped.encoded.write({msg: '{"beep":"boop"}', context: [] }) // {msg: {beep: "boop"}, context: [] }