Skip to content

Instantly share code, notes, and snippets.

@trustmaster
Created April 5, 2016 20:08
Show Gist options
  • Save trustmaster/c7117776d2aab3a18fecffa7f44ae5ac to your computer and use it in GitHub Desktop.
Save trustmaster/c7117776d2aab3a18fecffa7f44ae5ac to your computer and use it in GitHub Desktop.
Bracket forwarding the quick way
noflo = require 'noflo'
parser = require 'js-yaml'
exports.getComponent = ->
c = new noflo.Component
c.description = 'Parse YAML to an object'
c.inPorts.add 'in',
datatype: 'string'
description: 'YAML source'
c.outPorts.add 'out',
datatype: 'object'
c.outPorts.add 'error',
datatype: 'object'
required: false
c.ordered = true # Maintain order
c.process (input, output) ->
data = input.get 'in'
unless data.type is 'data'
return output.sendDone out: data # Forward brackets
unless data.data
output.sendDone
out: {}
return
try
result = parser.load data.data
catch e
output.sendDone
error: e
return
result = {} if result is null
output.sendDone
out: result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment