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

argjson

v1.1.1

Published

argv parser for node.js

Downloads

3

Readme

argjson

GitHub license GitHub last commit

GitHub top language GitHub code size in bytes GitHub release (latest by date)

Code Grade Code Grade

:uk: an argument parser for node.js

:fr: un parser d'arguments pour node.js.

https://github.com/cmames/argjson


Why

it's always useful and avoids having to code everything according to the types and number of arguments.

Pourquoi

c'est toujours utile et ça évite d'avoir à tout coder en fonction des types et du nombre d'argument.


Installation

npm install argjson

Installation

npm install argjson

Usage

import the package in your node file

const argjson=require("argjson");

create your menu options by calling the add method

argjson.add({
        arg: "file",
        short: "f",
        description: "file to open",
        default:""
});

arg : the name of the argument

short : the short name of the argument

description : the description of the argument

default : the default value of the argument

In the previous example we created the argument --file or -f

For on/off arguments like verbose we can do

argjson.add({
        arg: "verbose",
        short: "v",
        description: "verbose mode",
        default:false
});

in this case and only in this case default is optional and we have created --verbose or -v

-v will be different from -V

the --help or -h argument is already defined by default and displays the help

you can concatenate the short arguments

-a -b -c is equivalent to -abc -a -b -c -f myfile is equivalent to -abcf myfile

you can pass arrays and json as arguments

argjson.add({
        arg: "tab",
        short: "t",
        description: "array",
        default:[]
});
argjson.add({
        arg: "json",
        short: "j",
        description: "json",
        default:{}
});

once the arguments are defined, you just have to launch the parser

var argv=argjson.parse();

then you find in argv all the arguments with their long name

argv.file
argv.verbose
argv.tab
argv.json

the syntax argv["file"] also works

example of use

node myfile.js --file test.txt --tab "[1, 3, 5, 42]" --size 1024 --factor 1.27 -vxc

Utilisation

importez le paquet dans votre fichier node

const argjson=require("argjson");

créez vos option de menu en appelant la méthode add

argjson.add({
        arg: "file",
        short:"f",
        description:"file to open",
        default:""
});

arg : le nom de l'argument

short : le nom court de l'argument

description : la description de l'argument

default : la valeur par défaut de l'argument

Dans l'exemple précédent on a créé l'argument --file ou -f

Pour des arguments on/off comme verbose on peut faire

argjson.add({
        arg: "verbose",
        short:"v",
        description:"verbose mode",
        default:false
});

dans ce cas et seulement dans ce cas default est facultatif et on a créé --verbose ou -v

-v sera différent de -V

l'argument --help ou -h est déjà défini par défaut et affiche l'aide

vous pouvez concaténer les arguments courts

-a -b -c est équivalent à -abc -a -b -c -f monfichier est equivalent à -abcf monfichier

vous pouvez passer comme argument des tableaux et des json

argjson.add({
        arg: "tab",
        short:"t",
        description:"array",
        default:[]
});
argjson.add({
        arg: "json",
        short:"j",
        description:"json",
        default:{}
});

une fois les arguments définis il suffit de lancer le parser

var argv=argjson.parse();

vous retrouvez alors dans argv tous les arguments avec leur nom long

argv.file
argv.verbose
argv.tab
argv.json

la syntaxe argv["file"] fonctionne aussi

exemple d'utilisation

node monfichier.js --file test.txt --tab "[1, 3, 5, 42]" --size 1024 --factor 1.27 -vxc