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

micro-command

v0.1.1

Published

Small Node.js command interpreter

Downloads

6

Readme

Micro-Command is a minimal command-line interpreter

Micro-Command is not flashy but it will do the job swiftly and quickly. Unlike other interpreters feed in a string and recieve it as an object, great for live interactions and not initialisations. You do not need to initialise any commands, it will simply return the command as an object with any variables.

Example apps

save.js

const { MicroCLI } = require('micro-command');
let Micro = new MicroCLI();

let data = "Example data";
Micro.Parse("save --file C:\\Users\\x\\Documents --title \"Hello world\" -vo").then(x => {
    if (x.save) {
        if (x.save.file) {
            if (x.save.v || x.save.verbose) console.log(`Saving ${x.save.title ? x.save.title : "Placeholder"} to ${x.save.file}`);
            saveFunction(data, x.save.file, x.save.title ? x.save.title ? "Placeholder");
            if (x.save.v || x.save.verbose) console.log(`Saved ${x.save.title ? x.save.title : "Placeholder"} to ${x.save.file}`);
            if (x.save.o || x.save.open) {
                if (x.save.v || x.save.verbose) console.log(`Opening ${x.save.file}`);
                openFunction(x.save.file);
            }
        }
    } else if (x.delete) {
        //Do deletion stuff
    }
});

Parse Object (x)

{ 
	save: { 
		file: 'C:\\Users\\x\\Documents',
		title: 'Hello world',
		v: true,
		o: true 
	} 
}

account.js

const { MicroCLI } = require('micro-command');
let Micro = new MicroCLI();

Micro.Parse("account history --no-time").then(x => {
    console.log(x);
    if (x.account) {
        if (x.account.history) {
            console.log(getHistory(x.account.time)); //Don't output time
        }
    }
});

Parse Object (x)

{ 
	account: { 
		history: { 
			time: false
		}
	}
}

Command structure

There are 3 components to a command: command, flag, variable No part is required, parsing just commands, or just options and variables is fine.

Command

These are at the start of the command, any word not prefixed with - or " will be interpreted as a command, in the Parse return commands are objects.

In this example both foo and bar are commands

foo bar --baz qux

Flag

Flags are represented by a prefixed double hyphen, hyphen -- or --- is used for word options such as --file- is used for single char options such as -v or -vo Single char options can be grouped, so -vo will act as 2 variables v and o - both being true

To negate options append no- to the prefix, this will turn everything into false, i.e. --no-open, -no-o, -no-vo

Variable

Variables pair to the option before, --number 4 will resolve to { number: 4 }. Variables can be strings, numbers, or booleans. Variables cannot be paired with multiple single character options. -xyz foo is not allowed, -x foo is allowed.

String

Multi-word strings must be surrounded by speech " marks, single words do not

--title Example

--title "Hello World"

-t Foo

--file C:\\Users\\x\\Documents

####Numbers Integers and floats can be used and will be resolved into a number type

--size 4

--size 1.2

-s 5

####Booleans By default by including a flag sets it to true, prefixing the flag with no- will set the flag to false, not mentioning a flag leaves it as null; to check if a flag is false check x.bool != null && !x.bool

--verbose
--verbose true

-no-v
-v false