0.1.2 • Published 5 months ago

esc4sh v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

esc4sh

npm coverage build license

Escape a string to use it in shell. Support both linux and windows (cmd and powershell).

Install

yarn add esc4sh

Usage

Auto detect os and shell (not working in browser):

import { Manager } from "esc4sh";

const manager = new Manager();
manager.escape("something");

// use Array.map to escape multiple strings
// and join them with space to form an executable command
const cmd = ["curl", ...options.map((o) => manager.escape(o))].join(" ");

Explicitly specify shell. These can be used in browser.

import { esc4sh, esc4cmd, esc4ps, esc } from "esc4sh";

// linux sh/bash
console.log(esc4sh("$PATH")); // => '$PATH'
// windows cmd
console.log(esc4cmd("%PATH$")); // => "%PATH%"
// windows powershell
console.log(esc4ps("$env:PATH")); // => '$env:PATH'

// escape by options
esc(""); // for linux sh/bash
esc("", { windows: true }); // for windows cmd
esc("", { windows: true, powershell: true }); // for windows powershell

Helpers (not working in browser).

import { isWindows, isCmd, isPowershell } from "esc4sh";

isWindows(); // => boolean
isCmd(); // => boolean
isPowershell(); // => boolean

Credit

This project is inspired by xxorax/node-shell-escape and boazy/any-shell-escape.

CHANGELOG

0.1.2

5 months ago

0.1.1

6 months ago

0.1.0

6 months ago