
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
argv-split
Advanced tools
Split argv(argument vector) and handle special cases, such as quoted values.
Split argv(argument vector) and handle special cases, such as quoted or escaped values.
const split = require('split')
const mkdir = 'mkdir "foo bar"'
mkdir.split(' ') // ['mkdir', '"foo', 'bar"'] -> Oops!
split(mkdir) // ['mkdir', 'foo bar'] -> Oh yeah!
const mkdir2 = 'mkdir foo\\ bar'.split(' ')
mkdir2.split(' ') // ['mkdir', 'foo\\', 'bar'] -> Oops!
split(mkdir2) // ['mkdir', 'foo bar'] -> Oh yeah!
argv-split
handles all special cases with complete unit tests.# shell command: javascript array:
foo a\ b # ['foo', 'a b']
foo \' # ['foo', '\\\'']
foo \" # ['foo', '\\"']
foo "a b" # ['foo', 'a b']
foo "a\ b" # ['foo', 'a\\ b']
foo '\' # ['foo', '\\']
foo --abc="a b" # ['foo', '--abc=a b']
foo --abc=a\ b # ['foo', '--abc=a b']
# argv-split also handles line feeds
foo \
--abc=a\ b # ['foo', '--abc=a b']
# etc
split('foo \\\n --abc=a\\ b') // ['foo', '--abc=a b']
UNMATCHED_SINGLE
If a command missed the closing single quote, the error will throw:
Shell command:
foo --abc 'abc
try {
split('foo --abc \'abc')
} catch (e) {
console.log(e.code) // 'UNMATCHED_SINGLE'
}
UNMATCHED_DOUBLE
If a command missed the closing double quote, the error will throw:
foo --abc "abc
ESCAPED_EOF
If a command unexpectedly ends with a \
, the error will throw:
foo --abc a\# if there is nothing after \, the error will throw
foo --abc a\ # if there is a whitespace after, then -> ['foo', '--abc', 'a ']
NON_STRING
If the argument passed to split
is not a string, the error will throw
split(undefined)
$ npm i argv-split
Splits a string, and balance quoted parts. The usage is quite simple, see examples above.
Returns Array<string>
Join the given array of argument vectors into a valid argument string
New in 3.1.0
Array<string>
arguments to be joinedObject=
string="
should we use single quote or double quote when a certain argument needs to be quoted. Defaults to "
'command ' + join(['foo "bar', "'baz"])
// command "foo \"bar" "'baz"
There is a special value of split.LF
which could help us to create valid commands with line feeds:
'kubectl' + join(['apply', '--prune', '-f', 'manifest.yaml', split.LF, '-l', 'app=nginx'])
// kubectl apply --prune -f manifest.yaml \
// -l app=nginx
MIT
FAQs
Split argv(argument vector) and handle special cases, such as quoted values.
The npm package argv-split receives a total of 8,919 weekly downloads. As such, argv-split popularity was classified as popular.
We found that argv-split demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.