Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 27 lines (20 sloc) 0.841 kB
cbb1912 @chriso Added initial built-in modules
authored
1 usage = '''
2 This module evaluates an expression on each line of input and emits the result (unless the result is null)
3
4 1. To convert a TSV (tab separated file) to CSV
5 $ cat data.tsv | node.io -s eval "input.split('\t').join(',')" > data.csv
6
7 2. To remove empty lines from text.txt
8 $ cat text.txt | node.io -s eval "input.length ? input : null" > modified.txt
9 '''
10
11 nodeio = require 'node.io'
12
13 class EvalExp extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
14 init: ->
cbb1912 @chriso Added initial built-in modules
authored
15 if @options.args.length is 0
205e5fb @chriso Fixed the eval builtin
authored
16 @exit 'Please enter an expression, e.g. `node.io eval "input.length"`'
ee2496c @chriso Updated built-in modules
authored
17 if @options.args[0] is 'help'
205e5fb @chriso Fixed the eval builtin
authored
18 @status usage
19 @exit
20
cbb1912 @chriso Added initial built-in modules
authored
21 run: (input) ->
ee2496c @chriso Updated built-in modules
authored
22 result = eval @options.args[0]
0084cbd @chriso Fix eval module
authored
23 if result? then @emit result else @skip()
cbb1912 @chriso Added initial built-in modules
authored
24
25 @class = EvalExp
205e5fb @chriso Fixed the eval builtin
authored
26 @job = new EvalExp()
Something went wrong with that request. Please try again.