npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@valkyriestudios/node-args

v1.0.0

Published

An argument parser for node processes

Downloads

3

Readme

@valkyriestudios/node-args

A lightweight node script that reads and parses the arguments passed to a cli command, both converting them to their respective primitives and organizing them for easy access.

npm install @valkyriestudios/node-args

Example Output

The following is a series of example outputs for specific scenarios, showing the conversion of raw arguments to their primitives.

node myscript.js --fruits=bananas,apples,oranges --price=.1,.2,.3

{
    __bin: '/usr/bin/node',
    __script: '.../myscript.js',
    flags: {
        fruits: ['bananas', 'apples', 'oranges'],
        prices: [0.1, 0.2, 0.3],
    },
    args: [],
}
node myscript.js --no-filter --search

{
    __bin: '/usr/bin/node',
    __script: '.../myscript.js',
    flags: {
        filter: false,
        search: true,
    },
    args: [],
}
node myscript.js --price=8e-2

{
    __bin: '/usr/bin/node',
    __script: '.../myscript.js',
    flags: {
        price: 0.08,
    },
    args: [],
}
node myscript.js --foo=5.0124 -bar=false --foobar="abcdefg" --test=a,1,b,2 "Hello World" this,is,5

{
    __bin: '/usr/bin/node',
    __script: '.../myscript.js',
    flags: {
        foo: 5.0124,
        bar: false,
        foobar: "abcdefg",
        test: ["a", 1, "b", 2],
    },
    args: [
        "Hello World",
        ["this", "is", 5],
    ],
}

How does this work?

node-args uses process.argv, a node-native array of command line arguments and parses that array into an easy-to-use javascript object.

Getting Started

Simply import the library and execute it as a function. It will automatically return the parsed process arguments.

import NodeArgs from '@valkyriestudios/node-args';

const arguments = NodeArgs();

Configuration

Some aspects of the parsing can be controlled through a simple configuration object that you pass as a parameter to the node-args function.

An example of using this would be :

import NodeArgs from '@valkyriestudios/node-args';

const arguments = NodeArgs({
    delimiter: ';',
    c_numeric: false,
});

Options

  • c_array (default: true) Configures whether or not a string should be converted to an array if possible

  • c_bool (default: true) Configures whether or not a string should be converted to a boolean if possible

  • c_numeric (default: true) Configures whether or not a string should be converted to a number if possible

  • delimiter (default: ',') Sets the delimiter to be used to split a string into an array

  • bool_true_val (default: 'true') Configures what string represents a boolean true. e.g : '--harmony=true' will be parsed to { harmony: true }, whereas when bool_true_val is configured as '1', '--harmony=true' would be parsed to { harmony: 'true' }

  • bool_false_val (default: 'false') Configures what string represents a boolean false. e.g : '--harmony=false' will be parsed to { harmony: false }, whereas when bool_false_val is configured as '0', '--harmony=false' would be parsed to { harmony: 'false' }

Author

Contributors