transit = require('../../transit')
app = transit()
app.use transit.commandLine()
app.use transit.echo()
Allows to make a chain of formatting functions and register it as transit's formatter, like this:
app.formatOutput transit.chain uppercase, split, substituteName
transit = require('../../transit')
app = transit()
app.use transit.commandLine()
app.use transit.echo()
substituteName = (data, options, next) ->
next(data.replace(/{name}/gi, options?.name ? "Unknown"))
split = (data, next) ->
data.split(" ").forEach next
uppercase = (data) ->
data.toUpperCase()
In most cases it will be enight to use simplified syntax.
app.formatOutput transit.chain uppercase, split, substituteName
app.start()
app.sendBack 1, "hello, {name}!", {name: "Alex"}
will output
HELLO,
Alex!
There is a set of predefined formatting functions you may use:
app.formatOutput "myFormat", transit.chain transit.chain.json(),
transit.chain.splitByPortions(50),
transit.chain.wrapHtml()
Do not forget you may specify a name for formatter and call it by it.
app.sendBack.myFormat 1, {
message: "Hello",
type: "greeting",
mime: "application/json"
}