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

@arcaelas/command

v3.6.0

Published

If you are one of those who like to use terminals, you can create your own native commands using "command".

Downloads

65

Readme

Arcaelas Insiders Banner

Arcaelas Insiders Banner

Welcome to Arcaelas Insiders!

Hello, if this is your first time reading the Arcaelas Insiders documentation, let me tell you that you have found a good place to learn.

Our team and community are happy to write and make methods simple to implement and understand, but I think you already know that.

Let's start with the basic implementation steps.

> npm i --save @arcaelas/command
> yarn add --save @arcaelas/command

Implementation

// Class Import Statement
import Command from  '@arcaelas/command'

// commonjs
const { default: Command }  =  require('@arcaelas/command')

// tsconfig:
//	allowSyntheticDefaultImports: true
const Command  =  require('@arcaelas/command')

Command

Today a wide variety of applications have commands to simplify processes and be intuitive, for this reason the arcaelas development team has implemented a library dedicated to the construction of commands.

const serve  =  new Command({
	description: "Start server!"
});

Prompts

It's a simple thing, your command is already stored in the list of enabled commands for the environment. We could now assume that your command requires a list of parameters, including the port number where you want to run the server.

You can read documentation for inquirer in npm

const serve  =  Command({
	questions:{
		port:  {
			type: "number",
			default: 8080,
		}
	}
});

Your command now expects the given port number to be 8080, but in case the command runs like this:

serve --port 3000 Then the port property would be 3000 and not 8080.

Formats

We can also talk about formatting the expected data in a property, it could be the case that our application requires a specific type of data (string, object, number, array).

const serve  =  new Command({
	options:{
		id:{
			type: "number",
		},
		port:{
			type: "string",
			transformer(input, answers, flags){
				return Number( input )
			},
		}
	}
});

Whatever value is passed on the command line, the command handler will use the "Number" function to format the indicated data, this means that serve --port 3000 would result in the property port with the numeric value of 3000, while the command serve --port uno would return its value to NaN.

Another advantage of using Command is the implementation of arrays within its argument line, we could say that your command can only be executed with certain routes, you can indicate them like this serve --routes /home /dashboard /profile - -port 3000 Naturally, only the first value (/home) would be taken into account. To make it an array of values, we use the option with the Array type.

const serve  =  new Command({
	options:{
		port:{
			type:"number"
		},
		routes:{
			type: "checkbox",
		}
	}
})

Handler

Declaring properties and types is a very useful thing to do, but it's useless until you can read those values and make your command actually do what it's supposed to do.

To achieve this we use the action() property of the configurations.

const serve  =  new Command("serve",  {
	options:{
		port:{
			type: "number",
			default: 8080
		}
	},
	action(options: object, argv: string[]): any | Promise<any> {}
})

Now you can bring your command to life, from the action() function.

Execution

Everything seems to be very comfortable to implement and understand, but how do we call our command?


const serve  =  new Command({...});

// or using inherit method
serve.exec(["--port",  8080,  "--routes",  "/home",  "/dashboard",  "/profile /configs"]);

// or using object
serve.exec({
	port: 8080,
	routes:[
		"/home",
		"/dashboard",
		"/profile",
		"/configs",
	]
});

// You can pass command line arguments
serve.exec( process.argv  );

¿Want to discuss any of my open source projects, or something else?Send me a direct message on Twitter. If you already use these libraries and want to support us to continue development, you can sponsor us at Github Sponsors.