UNPKG

fsnip

Version:

Command line utility to extract and modify text or json from a file

59 lines (54 loc) 1.6 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.runOption = runOption; var _require = require('./textSnip.js'), textFrom = _require.textFrom, textTo = _require.textTo; var _require2 = require('./jsonSnip.js'), _json = _require2.json, jsonPrettify = _require2.jsonPrettify, jsonEllipsify = _require2.jsonEllipsify, jsonSnippet = _require2.jsonSnippet, jsonDelKeys = _require2.jsonDelKeys; function runOption(option, args, inpObj) { // option is a string eg. '-jsonEllipsify' // arguments is an array of arguments for the option // inpObj is an object containing the text, type and json object we need to modify // this function acts as a marsheller to identify options and process them accordingly var funcs = { '--json': function json() { _json(inpObj); }, '--prettify': function prettify() { jsonPrettify(inpObj, args); }, '--ellipsify': function ellipsify() { jsonEllipsify(inpObj, args); }, '--snip': function snip() { jsonSnippet(inpObj, args); }, '--delKeys': function delKeys() { jsonDelKeys(inpObj, args); }, '--from': function from() { textFrom(inpObj, args, false); }, '--start': function start() { textFrom(inpObj, args, true); }, '--to': function to() { textTo(inpObj, args, false); }, '--finish': function finish() { textTo(inpObj, args, true); } }; if (funcs[option]) { funcs[option](); } else { inpObj.error.push("invalid option '" + option + "' for fsnip"); } }