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

argv-split

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argv-split - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

package.json
{
"name": "argv-split",
"version": "0.1.0",
"version": "0.1.1",
"description": "Split argv(argument vector) and handle special cases, such as quoted values.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,3 +9,3 @@ # argv-split [![NPM version](https://badge.fury.io/js/argv-split.svg)](http://badge.fury.io/js/argv-split) [![Build Status](https://travis-ci.org/kaelzhang/node-argv-split.svg?branch=master)](https://travis-ci.org/kaelzhang/node-argv-split) [![Dependency Status](https://gemnasium.com/kaelzhang/node-argv-split.svg)](https://gemnasium.com/kaelzhang/node-argv-split)

'--abc "a b c"'.split(' ');
// -> ['--abc', '"a', 'b', 'c"'] -> Oooooooooops!
// ['--abc', '"a', 'b', 'c"'] -> Oooooooooops!
```

@@ -25,7 +25,30 @@

split('--abc "a b c"');
// ['--abc', 'a b c']
// ['--abc', 'a b c'], Oh yeah !!!!
```
### split(string)
Splits a string, and balance quoted parts.
```js
split('--abc "a \'b\' c"'); // ['--abc', "a 'b' c"]
split('--abc "a b c'); // ['--abc', '"a', 'b', 'c']
```
### split.balance(array)
Balances an array and join incorrect splited parts.
```js
split.balance(['--abc', '"a', 'b"']); // ['--abc', 'a b']
```
### split.join(array, [quote='])
```js
split.join(['--abc', 'a b']); // '--abc "a b"'
```
## License
MIT
'use strict';
var expect = require('chai').expect;
var argv_split = require('../');
var split = require('../');
// #4
var command = 'command -a "a \'b\' c" -b \'a "b" c\' -c'
+ ' "a b" -d \'a b\' -e "a" -f \'a\' -g "a b c';
var args = [
'command',
'-a', "a 'b' c",
'-b', 'a "b" c',
'-c', 'a b',
'-d', "a b",
'-e', 'a',
'-f', "a",
'-g', '"a', 'b', 'c'
];
describe("split(string)", function(){
it("quoted", function(){
expect(split(command)).to.deep.equal(args);
});
it("normal", function(){
var command = 'command -a b --abc false';
expect(split(command)).to.deep.equal([
'command',
'-a',
'b',
'--abc',
'false'
]);
});
});
describe("split.balance()", function(){
it("balance arguments", function(){
var splited = command.split(' ');
expect(split.balance(splited)).to.deep.equal(args);
});
});
describe("split.join()", function(){
it("join arguments", function(){
var args = [
'-a',
'a b c'
];
expect(split.join(args)).to.equal('-a \'a b c\'');
});
it("specified quote", function(){
var args = [
'-a',
'a b c'
];
expect(split.join(args, '"')).to.equal('-a "a b c"');
});
});
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