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

shell-encode

v0.2.1

Published

Escape Bash, PowerShell, CMD and mixed shell CLI commands

Readme

shell-encode

Escape Bash, PowerShell, CMD and mixed shell CLI commands.

Node.js CI License: MIT Run on Repl.it

Note that this package is in early stages of development and there may be breaking changes within semantically compatible versions. See change log.

Installation

With yarn:

yarn add shell-encode

Or with npm:

npm install --save shell-encode

Has no dependencies. TypeScript types defined.

Usage

Import:

const shellEncode = require('shell-encode');

ES6 syntax:

import shellEncode from 'shell-encode';

Basic Usage:

The method shellEncode(), encodes a CLI command specified as arguments. The result is ready to use as a CLI command for the specified shell. The default shell is bash, but can be changed.

var cmd = shellEncode('echo', ['Hello "World"!']);
console.log(cmd);
// Output: echo 'Hello "World"!'

To change the shell, add an options object as the last argument.

For example:

var cmd = shellEncode('echo', ['Hello "World"!'], { shell: 'cmd' });
console.log(cmd);
// Output: echo Hello^ \"World\"^!

Nested Arguments

Specifiying an array instead of a string combines the contents of the array into a single string argument. This is usefull when you want to pass nested arguments.

For example:

// cmd.run with testscript2, which has its own arguments:
var cmd = shellEncode('cmd.run', ['./testscript2', ['arg1', 'arg2']]);
console.log(cmd);
// Output: cmd.run "./testscript2 'arg1 arg2'"

Cross-Shell Encoding

You may want to call another shell from within a command. Specify the nested shell options as the last argument or item of the argument array.

For example:

// Call PowerShell from within CMD:
var cmd = shellEncode(
    'powershell', [
        'Write-Output', ['Hello World!'], { shell: 'powershell' }
    ], { shell: 'cmd' });
console.log(cmd);
// Output: powershell Write-Output^ 'Hello^ World^!'

Also have a look at the examples folder.

Changing the Default Shell

shellEncode.setDefaults('powershell');

Shell Specific Notes

CMD

  • Multiple lines are merged into a single line.
  • You need to wrap each pipe in an array as CMD escapes the line multiple times. For example, if there is a single pipe, CMD will escape commands before the pipe once and will escape commands after the pipe twice.

PowerShell

  • Multiple lines are merged into a single line.