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 🙏

© 2025 – Pkg Stats / Ryan Hefner

baker-js

v1.1.1

Published

Baker lets you easily add a command line interface to your node scripts.

Readme

baker

Baker lets you easily add a command line interface to your node scripts. It is inspired by python baker library (https://pypi.python.org/pypi/Baker/1.3)

Install

npm install baker-js

Usage

examples/basic.js

const baker = require('baker-js');

function run(a, b, c) {
  console.log("Run", a, b, c);
}

function tester(a, rest, options) {
  console.log("Test", a, rest, options);
}


if (require.main === module) {
  baker.command(tester, { command: "test", args: "rest", opts: "options" });
  baker.command(run, { default: true, required: ["a"] });

  baker.run();
}

output

$ node examples/basic.js --help
Usage: basic.js COMMAND <options>
Available commands: 
    test
    run
$ node examples/basic.js run --help
Usage: basic.js, run a <b> <c>

Required Arguments:
  a
Options:
  --b
  --c
$ node examples/basic.js run 1 2 3
Run 1 2 3

$ node examples/basic.js test 1 2 3 4 --five 5 --six 6 7
Test 1 [ 2, 3, 4, 7 ] { five: 5, six: 6 }

Options

baker.command(func, options)
@param Function func
@param Object options
@param String options.command name of command, defaults to function name.  Requried for anonymous functions.
@param Boolean options.default If true this function will run if no command name given on command line.
@param Array options.required List of requried args.  Script will eixt with error if arg not found on command line.
@param String options.opts Name of parameter to recieve object with all unmatche named commandline args.
@param String options.args Name of parameter to recieve an array of unmatched positional command line args.

Promises

When a promise is returned by the command function baker will wait till the promise is resolved and return the result of the promise

const baker = require('baker-js');
const request = require('request-promise');

function run() {
  return request('https://github.com/gabe0x02/baker-js').then((body) => {
    return `${body.trim().substring(0, 15)}...`;
  });
}

if (require.main === module) {
  baker.command(run, { default: true });
  baker.run();
}

output

$ node examples/promise.js 
<!DOCTYPE html>...

Generators

Baker also supports co generator flow control. (https://github.com/tj/co) Simply pass in a generator and write some synchronous looking code..

generator_example.js

const baker = require('baker-js');
const request = require('request-promise');

function *run() {
  const start = new Date();
  console.log("Start");
  const body = yield request('https://github.com/gabe0x02/baker-js');
  console.log("End");
  console.log("Length:", body.length, "chars");
  console.log("Duration:", new Date() - start, "ms");

  return `${body.trim().substring(0, 15)}...`;
}

if (require.main === module) {
  baker.command(run, { default: true });
  baker.run();
}

output

$ node examples/generator.js 
Start
End
Length: 56287 chars
Duration: 744 ms
<!DOCTYPE html>...

TODO

  • More testing in could be useful.
  • Better usage output
  • Allow argument descriptions in usage
  • Better documentation of options. args, opts, default, etc
  • post to npm