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

vorpal-setorprint

v1.0.1

Published

Quickly create vorpal commands which set a value, or print it if no argument was given.

Downloads

7

Readme

Vorpal - SetOrPrint

Build Status

A Vorpal.js extension for quickly creating commands which set a value, or print it if no argument was given. Think instant getters/setters for the console.

Installation

npm install vorpal-setorprint
npm install vorpal

Getting Started

const vorpal = (require('vorpal'))();
const vorpalSOP = require('vorpal-setorprint');

vorpal.use(vorpalSOP)
  .delimiter('vorpal-setorprint demo $')
  .show();

const sop = vorpal.sop;
const options = {foo: 'bar'};

sop.command('foo', options);
$ node ./myapp.js
vorpal-setorprint demo $ help foo

Usage: foo [options] [foo]


set or print foo

Options:

  --help  output usage information

vorpal-setorprint demo $ foo
bar
vorpal-setorprint demo $ foo qux
vorpal-setorprint demo $ foo
qux
vorpal-setorprint demo $

Usage

Adds a sop object to vorpal, which stores options and provides a command function.

command(key, obj[, options]): Adds a command to vorpal which either sets or prints a specific value. Returns the command object, just like vorpal.command does. This allows convenient chaining, e.g.

sop.command(key, obj)
  .alias('foobar')
  .description('I like trains.');
  • obj, key: When the added command is called without arguments, obj[key] is printed to the user. When the command is called with an argument, obj[key] is set to this argument. key is also the name of the added command.
  • options: The following values of the option object are used:
    • validate: an optional function to validate and parse the input. Receives args[key] and should return either the value for obj[key], or null, in which case obj[key] remains unchanged.
    • print: The function to be called when the added command is run without arguments. Defaults to sop.options.print.
    • failedValidation: A function which is called when validate returns null. Defaults to sop.options.failedValidation.
    • passedValidation: A function which is called when validate does not return null. Defaults to sop.options.passedValidation.

See the example here for a simple usage of all the options.

Options

The following options passed by vorpal.use(vorpalSOP, options) are used:

  • print: a function to be called with the value to print if no argument was given a sop-command. The default function tries to use vorpal-log's logger.info(arg) and falls back to either vorpal.activeCommand.log or vorpal.log.
  • describe: a function to be called with the key of each added command. The return value is used as the description for the help entry. Defaults to return "set or print #{key}". This value can simply be overridden by calling vorpal's description method on the command object returned by sop.command.
  • failedValidation: a function to be called with key, arg when an input fails to pass validation. arg is the argument as parsed by vorpal. By default, this prints "#{arg} is an invalid value for #{key}".
  • passedValidation: a function to be called with key, arg and value when an input passes validation. arg is the argument as parsed by vorpal, value is what the validate function returned. By default, this prints "set #{key} to #{arg}".