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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lieutenant

v1.1.0

Published

A command-line router

Readme

Build Status

Lieutenant

I made a router for a command-line app I was making, and this is it!

I wanted to build an app that worked less like a traditional *nix app, with its series of "-t 13" and "--other-option=yesplz" key-value arguments, and more like git, in those parts where you give word commands like "stash pop" and "branch".

Usage

To make a command-line app, preheat your oven to 176.7°C and type:

const router = require('lieutenant')

router({
	double(number) {
		if (typeof number === "undefined" || isNaN(number)) {
			console.log('wat')
		} else {
			console.log(parseFloat(number) * 2)
		}
	}
})

Run your app with example.js double 13 and it will spit 26 right back at you.

But who has time to type out whole words? Lieutenant lets you type in as few characters as you want, as long as it's enough to uniquely identify a command. example.js d 13 will work just as well.

You don't have to specify the arguments, Lieutenant doesn't care, it will pass them all in so you can handle any number of values for a command:

router({
	add(...args) {
		console.log(args.reduce(
			(a, b) => parseFloat(a) + parseFloat(b))
		)
	}
})

and example.js add 3 4 5 => 12 just like you'd hope.

But maybe that's not why you're here - maybe you're holding out for some real routing, some recursion!

router({
	test: {
		even(n) {
			const even = parseInt(n) % 2 === 0
			console.log("That's " + (even ? "" : "not ") + "even!")
		},
		odd(n) {
			const even = parseInt(n) % 2 === 0
			console.log('That's ' + (even ? 'not ' : ') + 'odd!')
		}
	}
})

But hey, what if you want people to just example.js test without specifying anything else? Don't worry; there's a hack for that. Just add a default property:

router({
	test: {
		even(n) {
			const even = parseInt(n) % 2 === 0
			console.log('That's ' + (even ? ' : 'not ') + 'even!')
		},
		odd(n) {
			const even = parseInt(n) % 2 === 0
			console.log('That's ' + (even ? 'not ' : ') + 'odd!')
		},
		default() {
			console.log('I just checked, and your computer is still on.')
		}
	}
})

Default output

If the user passes in arguments that aren't valid, Lietenant doesn't give them any hints about which commands are valid. If you want your app to say something useful in those cases, you'll have to write it yourself.

You can supply your custom error-handling by passing a function as the second argument to the routing function:

router({
	add(...args) {
		console.log(args.reduce(
			(a, b) => parseFloat(a) + parseFloat(b)
		))
	}
}, function badRoute(...args) {
	console.log('Type in double or add or test or something, not those dumb', args.length, 'words you did')
})

As Relient K said in that one song they wrote back when they were still styling a catchy bassline, the rest is up to you!

License

WTFPL