UNPKG

5.16 kBJavaScriptView Raw
1// Generated by LiveScript 1.6.0
2(function(){
3 var minimist, camelize, ref$, map, split, matchStr, pipe, replace, fromPairs, ifElse, identity, OUTPUT_TYPES, INPUT_TYPES, formatEnumList, HELP, parseAliases, wrapInParens, startsWith, wrapFunction, wrapNumberLookup, parse, help, out$ = typeof exports != 'undefined' && exports || this;
4 minimist = require('minimist');
5 camelize = require('camelize');
6 ref$ = require('ramda'), map = ref$.map, split = ref$.split, matchStr = ref$.match, pipe = ref$.pipe, replace = ref$.replace, fromPairs = ref$.fromPairs, ifElse = ref$.ifElse, identity = ref$.identity;
7 OUTPUT_TYPES = ['pretty', 'raw', 'csv', 'tsv', 'table'];
8 INPUT_TYPES = ['raw', 'csv', 'tsv'];
9 formatEnumList = compose$(function(it){
10 return it.join(', ');
11 }, (function(it){
12 return 'one of: ' + it;
13 }));
14 HELP = "Usage: ramda [options] [function] ...\n\n -f, --file read a function from a js/ls file instead of args; useful for\n larger scripts\n -c, --compact compact output for JSON and tables\n -s, --slurp read JSON objects from stdin as one big list\n -S, --unslurp unwraps a list before output so that each item is formatted and\n printed separately\n -t, --transduce use pipeline as a transducer to transform stdin\n -P, --json-path parse stream with JSONPath expression\n -i, --input-type read input from stdin as (" + formatEnumList(INPUT_TYPES) + ")\n -o, --output-type format output sent to stdout (" + formatEnumList(OUTPUT_TYPES) + ")\n -p, --pretty pretty-printed output with colors, alias to -o pretty\n -D, --pretty-depth set how deep objects are pretty printed\n -r, --raw-input alias for --input-type raw\n -R, --raw-output alias for --output-type raw\n -n, --no-stdin don't read input from stdin\n --[no-]headers csv/tsv has a header row\n --csv-delimiter custom csv delimiter character\n --js use javascript instead of livescript\n -I, --import require module as a variable\n -C, --configure edit config in $EDITOR\n -v, --verbose print debugging information (use -vv for even more)\n --version print version\n -h, --help displays help\n\nIf multiple functions are given as strings, they are composed into a\npipeline in order from left to right, similarly to R.pipe.\n\nExamples:\n\n curl -Ls http://bit.do/countries-json | ramda 'take 5' 'pluck \\name' --pretty\n curl -Ls http://bit.do/countries-json | ramda 'find where-eq code: \\FI'\n curl -Ls http://bit.do/countries-json | ramda --js 'filter(c => test(/land$/, c.name))'\n seq 10 | ramda --raw-input --slurp 'map parse-int' sum\n npm install moment && date +%s | ramda -r --import m=moment 'm.unix'\n\n\nREADME: https://github.com/raine/ramda-cli";
15 parseAliases = pipe(matchStr(/-[a-z], --[a-z\-]+/ig), map(compose$(replace(/\B-/g, ''), split(', '))), fromPairs);
16 wrapInParens = function(str){
17 return "(" + str + ")";
18 };
19 startsWith = function(str){
20 return function(it){
21 return (it != null ? it.indexOf(str) : void 8) === 0;
22 };
23 };
24 wrapFunction = ifElse(startsWith('->'), wrapInParens, identity);
25 wrapNumberLookup = ifElse(function(it){
26 return it.match(/^.\d+$/);
27 }, wrapInParens, identity);
28 out$.parse = parse = function(argv){
29 var args;
30 argv = map(compose$(wrapFunction, wrapNumberLookup), argv.slice(2));
31 args = camelize(minimist(argv, {
32 string: ['file', 'input-type', 'output-type', 'json-path', 'csv-delimiter'],
33 boolean: ['compact', 'slurp', 'unslurp', 'pretty', 'verbose', 'version', 'raw-input', 'raw-output', 'configure', 'no-stdin', 'js', 'transduce', 'headers'],
34 alias: parseAliases(HELP),
35 'default': {
36 stdin: true,
37 headers: true,
38 'csv-delimiter': ','
39 }
40 }));
41 args._ = args[''];
42 delete args[''];
43 if (args.rawInput) {
44 args.inputType = 'raw';
45 }
46 if (args.rawOutput) {
47 args.outputType = 'raw';
48 }
49 if (args.pretty) {
50 args.outputType = 'pretty';
51 }
52 if (args.outputType != null && !in$(args.outputType, OUTPUT_TYPES)) {
53 throw new Error("Output type should be " + formatEnumList(OUTPUT_TYPES));
54 }
55 if (args.inputType != null && !in$(args.inputType, INPUT_TYPES)) {
56 throw new Error("Input type should be " + formatEnumList(INPUT_TYPES));
57 }
58 if (in$('-vv', argv)) {
59 args.veryVerbose = true;
60 }
61 if (in$('-n', argv)) {
62 args.stdin = false;
63 }
64 args['import'] = typeof args['import'] === 'string' && [args['import']] || args['import'];
65 return args;
66 };
67 out$.help = help = function(){
68 return HELP;
69 };
70 function compose$() {
71 var functions = arguments;
72 return function() {
73 var i, result;
74 result = functions[0].apply(this, arguments);
75 for (i = 1; i < functions.length; ++i) {
76 result = functions[i](result);
77 }
78 return result;
79 };
80 }
81 function in$(x, xs){
82 var i = -1, l = xs.length >>> 0;
83 while (++i < l) if (x === xs[i]) return true;
84 return false;
85 }
86}).call(this);