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

argv-split

Package Overview
Dependencies
Maintainers
0
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 3.0.0 to 3.1.0

41

index.js
'use strict'
module.exports = split
// split.join = join
split.join = join

@@ -158,3 +158,3 @@

if (typeof str !== 'string') {
type_error(`Str must be a string. Received ${str}`, 'NON_STRING')
type_error(`\`str\` must be a string. Received ${str}`, 'NON_STRING')
}

@@ -208,17 +208,28 @@

// function join (args, options = {}) {
// const quote = options.quote || "'"
const REGEX_NEED_QUOTE = /\s|"|'/
// return args.map(function (arg) {
// if (!arg) {
// return
// }
function join(args, {
quote = DOUBLE_QUOTE
} = {}) {
if (![SINGLE_QUOTE, DOUBLE_QUOTE].includes(quote)) {
type_error(
`\`options.quote\` must be either ${SINGLE_QUOTE} or ${DOUBLE_QUOTE}. Received ${quote}` , 'INVALID_QUOTE'
)
}
// return /\c+/.test(arg)
// // a b c -> 'a b c'
// // a 'b' -> 'a \'b\''
// ? quote + arg.replace("'", "\\'") + quote
// : arg
const process_arg = arg => {
if (!REGEX_NEED_QUOTE.test(arg)) {
return arg
}
// }).join(WHITE_SPACE)
// }
if (!arg.includes(quote)) {
return quote + arg + quote
}
// escape quote
const escaped = arg.replace(new RegExp(quote, 'g'), `\\${quote}`)
return quote + escaped + quote
}
return args.map(process_arg).join(WHITE_SPACE)
}
{
"name": "argv-split",
"version": "3.0.0",
"version": "3.1.0",
"description": "Split argv(argument vector) and handle special cases, such as quoted values.",

@@ -5,0 +5,0 @@ "files": [

@@ -93,18 +93,30 @@ [![Build Status](https://github.com/kaelzhang/node-argv-split/actions/workflows/nodejs.yml/badge.svg)](https://github.com/kaelzhang/node-argv-split/actions/workflows/nodejs.yml)

```sh
$ npm install argv-split --save
$ npm i argv-split
```
### split(string)
### split(string) -> Array<string>
Splits a string, and balance quoted parts. The usage is quite simple, see examples above.
Returns `Array`
Returns `Array<string>`
### ~~split.join()~~
### split.join(args, options?) -> string
Temporarily removed in `2.0.0`, and will be added in `2.1.0`
Join the given array of argument vectors into a valid argument string
New in `3.1.0`
- **args** `Array<string>` arguments to be joined
- **options?** `Object=`
- **quote** `string="` should we use single quote or double quote when a certain argument needs to be quoted. Defaults to `"`
```js
'command ' + join(['foo "bar', "'baz"])
// command "foo \"bar" "'baz"
```
## 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