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

ketch

v1.0.0

Published

Ketch helps you execute, one way or another.

Downloads

23

Readme

ketch

Ketch helps you execute, one way or another.

NPM Code Climate Test Coverage

Overview

Use this module to easily build commands for passing to child_process functions.

When called as a function, this module will return a new Ketch instance.

Installation

npm install ketch

Example:

var ketch = require('ketch');

// what branch am I on?
ketch('git')
  .prepend('/usr/bin/env')
  .push('symbolic-ref')
  .opt('quiet', 'short')
  .push('HEAD')
  .exec()
  // returns stdout, stderr as array
  .done(function(output) {
     console.log(output[0].trim());
  }, function(err) {
     throw err;
  });

// use a callback instead
ketch('git')
  .prepend('/usr/bin/env')
  .push('symbolic-ref')
  .opt('quiet', 'short')
  .push('HEAD')
  .exec(function(err, stdout, stderr) {
    if (err) {
      throw err;
    }
    console.log(stdout.trim());
  });

Class: Ketch

Provides chainable functions to easily build and execute a command.

last_err: String , Last error, if present
last_stdout: String , Last stdout value, if present
last_stderr: String , Last stderr value, if present
last_exec_cmd: String , Last command run with child_process.exec()
last_execFile_cmd: String , Last command run with child_process.execFile()
last_fork_cmd: String , Last command run with child_process.fork()
last_spawn_cmd: String , Last command run with child_process.spawn()
cmd: Array , Internal array representation of this command.

ketch.Ketch.parseArgs()

Parse function arguments into an array. arguments may be one of:

  • an array
  • a space-separated string
  • one or more strings (not separated by space)

Returns: Array, Command as an array

ketch.Ketch.append()

Append an argument or arguments to this command. Alias: push()

Returns: Ketch, Ketch instance

ketch.Ketch.prepend()

Prepend an argument or arguments to this command. Alias: unshift()

Returns: Ketch, Ketch instance

ketch.Ketch.opt()

Sugar function to append one or more options to the command.

Returns: Ketch, Ketch instance

Example:

ketch('git').opt('q', 'short') // becomes "git -q --short"

ketch.Ketch.toString()

Returns current command as a space-separated string.

Returns: String, String representation of this command

ketch.Ketch.pop()

Pops the last argument off of the command. Does not return it. If you need that, use ketch('foo').cmd.pop()

Returns: Ketch, Ketch instance

ketch.Ketch.shift()

Shifts the first argument off of the command. Does not return it. If you need that, use ketch('foo').cmd.shift()

Returns: Ketch, Ketch instance

ketch.Ketch.splice()

Splice the command.

Returns: Ketch, Ketch instance

ketch.Ketch.serialize()

"Serialize" this command into command/arguments array format, suitable for passing to execFile or fork. Aliases: get(), toJSON

Returns: Array, Array where first item is a string, second is array of commands

ketch.Ketch.exec(options, callback)

Wrapper around child_process.exec(). Returns a promise, or

Parameters

options: Object, Options for child_process.exec()

callback: function, If present, will execute as NodeJS-style callback; otherwise will return a Promise.

Returns: ChildProcess | Promise, ChildProcess instance if callback is specified, otherwise a Promise.

ketch.Ketch.execFile(options, callback)

Wrapper around child_process.execFile(). Returns a promise, or

Parameters

options: Object, Options for child_process.execFile()

callback: function, If present, will execute as NodeJS-style callback; otherwise will return a Promise.

Returns: ChildProcess | Promise, ChildProcess instance if callback is specified, otherwise a Promise.

ketch.Ketch.fork(options, callback)

Wrapper around child_process.fork(). Returns a promise, or

Parameters

options: Object, Options for child_process.fork()

callback: function, If present, will execute as NodeJS-style callback; otherwise will return a Promise.

Returns: ChildProcess | Promise, ChildProcess instance if callback is specified, otherwise a Promise.

ketch.Ketch.spawn(options, callback)

Wrapper around child_process.spawn(). Returns a promise, or

Parameters

options: Object, Options for child_process.spawn()

callback: function, If present, will execute as NodeJS-style callback; otherwise will return a Promise.

Returns: ChildProcess | Promise, ChildProcess instance if callback is specified, otherwise a Promise.

ketch.Ketch.clear()

Obliterates the current command. Alias: reset()

Returns: Ketch, Ketch instance

ketch.Ketch.debug()

Debugging function to log the current command to console. Chainable, for your pleasure.

Returns: Ketch, Ketch instance

ketch.Ketch.tap()

"Tap" into the chain.

Parameters

callback: function, Which will be passed the Ketch instance.

Returns: Ketch, Ketch instance

License

© 2014-2015, Christopher Hiller. Licensed MIT.