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

command-join

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

command-join - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

command-join.d.ts

201

command-join.js

@@ -1,106 +0,111 @@

'use strict'
const NEEDS_QUOTE = /[\s\\*\?\[\]`$()#<>|&;]/
"use strict";
const NEEDS_QUOTE = /[\s\\*\?\[\]`$()#<>|&;]/;
function joinNix(arr) {
let out = []
for (let command of arr) {
// whether we need a quote for the current block
let needsQuote = false
// collection of quoted strings and escaped single quotes
let blocks = []
// string collector
let currentBlock = []
let flushCurrentBlock = () => {
// skip if we don't have anything collected as the current block
if (!currentBlock.length) { return }
if (needsQuote) {
currentBlock.unshift("'")
currentBlock.push("'")
}
blocks.push(currentBlock.join(''))
currentBlock = []
const out = [];
for (const command of arr) {
// if it is an empty string then append an empty string indicator
if (command.length === 0) {
out.push("''");
continue;
}
// whether we need a quote for the current block
let needsQuote = false;
// collection of quoted strings and escaped single quotes
const blocks = [];
// string collector
let currentBlock = [];
const flushCurrentBlock = () => {
// skip if we don't have anything collected as the current block
if (!currentBlock.length) {
return;
}
if (needsQuote) {
currentBlock.unshift("'");
currentBlock.push("'");
}
blocks.push(currentBlock.join(''));
currentBlock = [];
};
for (const char of command) {
if (char === "'") { // if single quote
// flush the current block
flushCurrentBlock();
// escape a single quote
blocks.push("\\'");
continue;
}
if (NEEDS_QUOTE.test(char)) {
needsQuote = true;
}
currentBlock.push(char);
}
// flush last block
flushCurrentBlock();
const escapedCommand = blocks.join('');
out.push(escapedCommand);
}
for (let char of command) {
if (char === "'") { // if single quote
// flush the current block
flushCurrentBlock()
// escape a single quote
blocks.push("\\'")
continue
}
if (NEEDS_QUOTE.test(char)) {
needsQuote = true
}
currentBlock.push(char)
}
// flush last block
flushCurrentBlock()
let escapedCommand = blocks.join('')
out.push(escapedCommand)
}
return out.join(' ')
return out.join(' ');
}
function joinWin(arr) {
let out = []
for (let command of arr) {
if (!/[\s\\"<>|&]/.test(command)) {
out.push(command)
continue
const out = [];
for (const command of arr) {
// if it is an empty string then append an empty string indicator
if (command.length === 0) {
out.push('""');
continue;
}
if (!/[\s\\"<>|&]/.test(command)) {
out.push(command);
continue;
}
let backslashes = 0;
// start escape quote
const outString = ["\""];
const flushBackslashes = (n) => {
outString.push("\\".repeat(n * backslashes));
backslashes = 0;
};
for (let char of command) {
// if char is a backslash
if (char === "\\") {
// enqueue backslash
backslashes++;
}
// if char is a double quote
else if (char === "\"") {
// doubly end backslash sequence if any
flushBackslashes(2);
// push string \" to escape quote
outString.push("\\\"");
}
else {
// singly end backslash sequence if any
flushBackslashes(1);
outString.push(char);
}
}
// flush any remaining backslashes
flushBackslashes(2);
// end escape quote
outString.push("\"");
let escapedCommand = outString.join('');
// escape some special characters
escapedCommand = escapedCommand.replace(/[&|<>;%^]/g, match => `^${match}`);
out.push(escapedCommand);
}
let backslashes = 0
let c
// start escape quote
let outString = ["\""]
let flushBackslashes = (n) => {
outString.push("\\".repeat(n * backslashes))
backslashes = 0
return out.join(' ');
}
function commandJoin(arg) {
if (typeof arg === 'string') {
arg = [arg];
}
for (let char of command) {
// if char is a backslash
if (char === "\\") {
// enqueue backslash
backslashes++
}
// if char is a double quote
else if (char === "\"") {
// doubly end backslash sequence if any
flushBackslashes(2)
// push string \" to escape quote
outString.push("\\\"")
}
else {
// singly end backslash sequence if any
flushBackslashes(1)
outString.push(char)
}
arg = Array.from(arg);
if (process.platform === 'win32') {
return joinWin(arg);
}
// flush any remaining backslashes
flushBackslashes(2)
// end escape quote
outString.push("\"")
let escapedCommand = outString.join('')
// escape some special characters
escapedCommand = escapedCommand.replace(/[&|<>;%^]/g, match => `^${match}`)
out.push(escapedCommand)
}
return out.join(' ')
else {
return joinNix(arg);
}
}
function commandJoin(arg) {
if (typeof arg === 'string') {
arg = [arg]
}
arg = Array.from(arg)
if (process.platform === 'win32') {
return joinWin(arg)
}
else {
return joinNix(arg)
}
}
module.exports = commandJoin
module.exports = commandJoin;
//# sourceMappingURL=command-join.js.map
MIT License
Copyright (c) 2015-2017 Sean Marvi Oliver Genabe
Copyright (c) 2015-2019 Sean Marvi Oliver Genabe

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "command-join",
"version": "2.0.0",
"version": "2.0.1",
"description": "Escape and join command-line arguments, cross-platform.",
"main": "command-join.js",
"scripts": {
"test": "mocha test/*.test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/seangenabe/command-join.git"
},
"keywords": [
"shell",
"argv",
"cli",
"command",
"escape",
"join",
"cli",
"argv"
"shell"
],
"author": "Sean Genabe <seangenabe@outlook.com>",
"license": "MIT",
"homepage": "https://github.com/seangenabe/command-join#readme",
"bugs": {
"url": "https://github.com/seangenabe/command-join/issues"
},
"homepage": "https://github.com/seangenabe/command-join#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/seangenabe/command-join.git"
},
"license": "MIT",
"author": "Sean Genabe <seangenabe@outlook.com>",
"main": "command-join.js",
"scripts": {
"build": "tsc",
"postinstall": "npx -p @seangenabe/tnx tnx || exit 0",
"prepublishOnly": "npm test",
"pretest": "npm run build",
"test": "node test/index.test.js",
"watch": "tsc -w"
},
"dependencies": {
"@improved/node": "^1.0.0"
},
"devDependencies": {
"chai": "^3.4.1",
"mocha": "^3.1.0"
"@types/node": "^12.0.2",
"t0": "^1.0.0",
"typescript": "^3.4.5"
},

@@ -31,0 +40,0 @@ "engines": {

@@ -6,7 +6,8 @@ # command-join

[![npm](https://img.shields.io/npm/v/command-join.svg?style=flat-square)](https://www.npmjs.com/package/command-join)
[![Travis Build Status](https://img.shields.io/travis/seangenabe/command-join/master.svg?label=travis&style=flat-square)](https://travis-ci.org/seangenabe/command-join)
[![AppVeyor Build Status](https://img.shields.io/appveyor/ci/seangenabe/command-join.svg?label=appveyor&style=flat-square)](https://ci.appveyor.com/project/seangenabe/command-join)
[![Build Status](https://img.shields.io/travis/seangenabe/command-join/master.svg?style=flat-square)](https://travis-ci.org/seangenabe/command-join)
[![devDependency Status](https://img.shields.io/david/dev/seangenabe/command-join.svg?style=flat-square)](https://david-dm.org/seangenabe/command-join#info=devDependencies)
[![node](https://img.shields.io/node/v/command-join.svg?style=flat-square)](https://nodejs.org/en/download/)
If you like this package, be sure to star its repo, and please consider [donating](https://seangenabe.netlify.com/donate).
## Usage

@@ -34,5 +35,1 @@

See the tests for more convoluted examples.
## License
MIT
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