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

visit-args

v0.1.0

Published

Visit application methods that map directly to command line arguments and emit events for flags.

Downloads

9

Readme

visit-args NPM version

Visit application methods that map directly to command line arguments and emit events for flags.

Install

Install with npm

$ npm i visit-args --save

Usage

First, an example, so the following docs make sense.

var argv = require('minimist');
var cli = require('visit-args');

// see the `app` example in `./examples/app.js` for details
var App = require('./examples/app');
var app = new App();

cli.on('set', function (key, val) {
  // do stuff with key/val 
});

cli.on('get', function (key, val) {
  // do stuff with key/val
});

cli.visit(app, argv(['--set=a', '--get=a']));

How this works

The idea is that app is an object with methods on it, and when a command line flag matches the name of a method on app, that method is called and is passed any additional arguments related to that method call (that's the tricky part: "additional arguments". Which is what this lib does - figure out how to invoke that method with the right arguments...)

Method arguments

This brings up the question: "What is passed to the method when it's called, if all we have is a command line flag?". That's a good question. This is easiest to explain by way of examples. Let's say you pass the following flag:

$ --a=b

Minimist would parse this to {a: 'b'}. Next, if you're application happens to have a method named a, then visit-args would invoke the method and pass b to it. A more meaningful example might be something like:

$ --del=foo

Which would invoke the del method on app, with the foo argument. In other words:

app.del('foo');

If, more often than not, your methods need more information than just a string or boolean to be able to take any kind of meaningful action, then it's worth considering using a library like expand-args, which will post-process arguments after minimist, but before visit-args, so that the following is possible:

$ --set=a:b

Which would invoke the following on app:

app.set('a', 'b');

See expand-args and expand-object for more details.

Related projects

  • expand-object: Expand a string into a JavaScript object using a simple notation. Use the CLI or… more
  • expand-args: Expand parsed command line arguments using expand-object.
  • minimist-plugins: Simple wrapper to make minimist pluggable. ~20 sloc.
  • minimist: parse argument options

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on August 07, 2015.