UNPKG

ramda-cli

Version:

A command-line tool for processing JSON with Ramda and LiveScript

92 lines (91 loc) 2.59 kB
// Generated by LiveScript 1.6.0 (function(){ var ref$, keys, props, map, toPairs, apply, objOf, type, merge, uniq, chain, ifElse, isNil, always, identity, Table, flat, objToObjs, STYLE, formatList, formatListOfObjs, formatObj, formatPrimitiveEtc; ref$ = require('ramda'), keys = ref$.keys, props = ref$.props, map = ref$.map, toPairs = ref$.toPairs, apply = ref$.apply, objOf = ref$.objOf, type = ref$.type, merge = ref$.merge, uniq = ref$.uniq, chain = ref$.chain, ifElse = ref$.ifElse, isNil = ref$.isNil, always = ref$.always, identity = ref$.identity; Table = require('@rane/cli-table'); flat = require('flat'); objToObjs = compose$(toPairs, map(apply(objOf))); STYLE = { head: ['cyan', 'bold'] }; formatList = function(list, opts){ var table; switch (type(list[0])) { case 'Object': return formatListOfObjs(list, opts); default: table = new Table(opts); list.forEach(function(it){ return table.push( (function(){ switch (type(it)) { case 'Array': return it; default: return [it]; } }())); }); return table.toString(); } }; formatListOfObjs = function(objs, opts){ var flatObjs, head, table, rows; flatObjs = map(flat, objs); head = uniq( chain(keys, flatObjs)); table = new Table(merge(opts, { head: head })); rows = map(props(head), flatObjs); rows.forEach(function(it){ return table.push(it); }); return table.toString(); }; formatObj = function(obj, opts){ var table; table = new Table(opts); objToObjs(flat(obj)).forEach(function(it){ return table.push(it); }); return table.toString(); }; formatPrimitiveEtc = function(x, opts){ var table; table = new Table(opts); table.push([x]); return table.toString(); }; module.exports = function(x, style){ var opts; style == null && (style = {}); opts = { style: merge(STYLE, style) }; return (function(it){ return it(x, opts); })( (function(){ switch (type(x)) { case 'Array': return formatList; case 'Object': return formatObj; default: return formatPrimitiveEtc; } }())); }; function compose$() { var functions = arguments; return function() { var i, result; result = functions[0].apply(this, arguments); for (i = 1; i < functions.length; ++i) { result = functions[i](result); } return result; }; } }).call(this);