
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Simple, lightweight argv parser. Powers the cleffa and clefairy packages
The argv parser behind cleffa and clefairy.
import { parseArgv } from "clef-parse";
// Sample argv
const result = parseArgv([
"--bundle",
"--input",
"index.js",
"--output",
"bundle.js",
"-v",
]);
console.log(result);
// Logs:
// {
// options: { bundle: true, input: 'index.js', output: 'bundle.js', v: true },
// positionalArgs: []
// }
// Optionally, you can provide type hints that will help the parser coerce values:
const result2 = parseArgv(
["--bundle", "--input", "index.js", "--output", "bundle.js", "-v"],
{
bundle: Boolean,
input: String,
output: String,
v: Boolean,
},
);
console.log(result2);
// Logs:
// {
// options: { bundle: true, input: 'index.js', output: 'bundle.js', v: true },
// positionalArgs: []
// }
// Valid hints are Number, Boolean, String, or Path. Number, Boolean, and String are the standard JS globals, but Path is the class from the npm package "nice-path", which is re-exported by clef-parse:
import { Path } from "clef-parse";
// When you provide the Path hint, clef-parse will interpret the input string as a path (relative to cwd unless it's absolute), and return a `Path` object. It will always be an absolute path.
const result3 = parseArgv(
["--bundle", "--input", "index.js", "--output", "bundle.js", "-v"],
{
bundle: Boolean,
input: Path,
output: Path,
v: Boolean,
},
);
console.log(result3);
// Logs (for example):
// {
// options: {
// bundle: true,
// input: Path {
// segments: [
// "",
// "home",
// "suchipi",
// "Code",
// "clef-parse",
// "index.js",
// ],
// separator: "/",
// },
// output: Path {
// segments: [
// "",
// "home",
// "suchipi",
// "Code",
// "clef-parse",
// "bundle.js",
// ],
// separator: "/",
// },
// v: true
// },
// positionalArgs: []
// }
// If you don't provide hints, clef-parse will do its best to guess.
See the TypeScript types in the source code for more information.
$ npm install -g clef-parse
$ clef-parse one two --three-four=five
{
"options": {
"threeFour": "five"
},
"positionalArgs": [
"one",
"two"
]
}
To specify hints with the CLI tool, use environment variables named like CLEF_PARSE_HINT_<option name goes here>
. For instance:
# Without any hints specified, --with-batteries is parsed as a string:
$ clef-parse some stuff --with-batteries yeah yup
{
"options": {
"withBatteries": "yeah"
},
"positionalArgs": [
"some",
"stuff",
"yup"
]
}
# But specifying the hint as boolean treats the next value as a positional arg:
$ env CLEF_PARSE_HINT_WITH_BATTERIES=Boolean clef-parse some stuff --with-batteries yeah yup
{
"options": {
"withBatteries": true
},
"positionalArgs": [
"some",
"stuff",
"yeah",
"yup"
]
}
MIT
FAQs
Simple, lightweight argv parser. Powers the cleffa and clefairy packages
The npm package clef-parse receives a total of 2,942 weekly downloads. As such, clef-parse popularity was classified as popular.
We found that clef-parse demonstrated a not healthy version release cadence and project activity because the last version was released 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.