Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-to-spawn-args

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-to-spawn-args - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

example/simple.js

21

index.js

@@ -7,8 +7,19 @@ module.exports = function(object, options){

var value = object[prop];
if (value){
output.push("--" + prop);
if (options.quote){
output.push("\"" + value + "\"");
if (value !== undefined){
if (prop.length === 1){
output.push("-" + prop);
if (value !== true){
if (options.quote){
output.push("\"" + value + "\"");
} else {
output.push(value);
}
}
} else {
output.push(value);
output.push("--" + prop);
if (options.quote){
output.push("\"" + value + "\"");
} else {
output.push(value);
}
}

@@ -15,0 +26,0 @@ }

{
"name": "object-to-spawn-args",
"version": "0.0.0",
"version": "0.1.0",
"description": "Converts an object to a child_process.spawn args array",

@@ -5,0 +5,0 @@ "repository": "https://github.com/75lb/object-to-spawn-args",

@@ -5,5 +5,42 @@ [![view on npm](http://img.shields.io/npm/v/object-to-spawn-args.svg)](https://www.npmjs.org/package/object-to-spawn-args)

[![Dependency Status](https://david-dm.org/75lb/object-to-spawn-args.svg)](https://david-dm.org/75lb/object-to-spawn-args)
![Analytics](https://ga-beacon.appspot.com/UA-27725889-25/object-to-spawn-args/README.md?pixel)
object-to-spawn-args
====================
#object-to-spawn-args
Converts an options object to an array suitable for passing to `child_process.spawn()`.
Single letter object properties (e.g. `c: "red"`) convert to short-option args (e.g. `-c red`). Longer object properties (e.g. `colour: "red"`) convert to long-option args (e.g. `--colour red`). Object property values equalling `true` convert to flags (e.g. `-l`).
This options object:
```js
var options = {
l: true,
c: "red",
man: "pete",
tramp: true
}
```
converts to
```js
[ "-l", "-c", "red", "--man", "pete", "--tramp" ]
```
##Installation
Move into your project directory then run:
```sh
$ npm install object-to-spawn-args --save
```
*Mac / Linux users may need to run with `sudo`*.
##Usage
```js
var toSpawnArgs = require("object-to-spawn-args");
var spawn = require("child_process").spawn;
var options = {
l: true,
a: true
};
spawn("ls", toSpawnArgs(options), { stdio: "inherit" });
```
var test = require("tap").test;
var toSpawnArgs = require("../");
test("simple", function(t){
test("long option", function(t){
var object = {

@@ -13,4 +13,13 @@ one: 1,

test("simple", function(t){
test("short option", function(t){
var object = {
l: true,
c: "red"
};
t.deepEqual(toSpawnArgs(object), [ "-l", "-c", "red" ]);
t.end();
});
test("with quotes", function(t){
var object = {
one: 1,

@@ -17,0 +26,0 @@ two: 2

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc