Skip to content

Latest commit

 

History

History
57 lines (36 loc) · 1.38 KB

process.md

File metadata and controls

57 lines (36 loc) · 1.38 KB

Process

Process utilities


Table of Contents


formatArgs(args, is_unix) : Array

Convert an Object of params to an Array of parsed command line args.

const formatArgs = require('nyks/process/formatArgs');

formatArgs({foo : 'foo', bar : 'bar'}); // return ["--foo=foo", "--bar=bar"]
formatArgs({foo : [1, 2, 3]}); // return ["--foo=1", "--foo=2", "--foo=3"]

parseArgs([argv]) : Object

Command line args parser, aligned on yks patterns.

const parseArgs = require('nyks/process/parseArgs');

parseArgs(["--foo"]); // return {args : [], dict : {foo : true}, rest : undefined}
parseArgs(["bar", "--foo", "baz"]); // return {args : ["bar", "baz"], dict : {foo : true}, rest : undefined}

// result of splitArgs('--foo=42 bar -- --this --is --unparsed') :
parseArgs([ '--foo=42', 'bar', '--', '--this --is --unparsed' ]); // return {args : ["bar"], dict : {foo : 42}, rest : "--this --is --unparsed"}

splitArgs(str) : Array

Split a string into whitespace separated chunks.

const splitArgs = require('nyks/process/splitArgs');

splitArgs("a 12 d"); // return ["a", 12, "d"]
splitArgs("a \"'b c'\" c  d") // return ["a", "'b c'", "c", "d"]