All Projects → chocolateboy → shell-escape-tag

chocolateboy / shell-escape-tag

Licence: Artistic-2.0 License
An ES6 template tag which escapes parameters for interpolation into shell commands

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to shell-escape-tag

boxquote.el
Quote text with a semi-box.
Stars: ✭ 16 (+14.29%)
Mutual labels:  quoting
fig.style
Quotes app for mobile (Android, iOS) & web
Stars: ✭ 74 (+428.57%)
Mutual labels:  quote
wikiquote
Retrieve quotes from any Wikiquote article.
Stars: ✭ 86 (+514.29%)
Mutual labels:  quote
random-data
随机数据产生姬
Stars: ✭ 21 (+50%)
Mutual labels:  template-string
zombie-escape
🏃 Gamemode for Garry's Mod based on the popular Counter-Strike: Source server mod
Stars: ✭ 17 (+21.43%)
Mutual labels:  escape
html-template-tag
📄 - ES6 Tagged Template for compiling HTML template strings
Stars: ✭ 45 (+221.43%)
Mutual labels:  template-string
EFT Flea Market Bot
Escape from Tarkov Flea Market bot, to generate a lot of in-game currency within shortest time, while not even having to actively play the game!
Stars: ✭ 22 (+57.14%)
Mutual labels:  escape
template-string-optimize-loader
template string optimize loader module for webpack
Stars: ✭ 15 (+7.14%)
Mutual labels:  template-string
Warri0r
ios 12 Sandbox escape POC
Stars: ✭ 32 (+128.57%)
Mutual labels:  escape
ansi-to-svg
😹 convert ANSI Escaped CLI strings to SVGs
Stars: ✭ 18 (+28.57%)
Mutual labels:  escape
motivate
⚡ motivate ⚡ - A simple script to print random motivational quotes. Highly influenced by linux command fortune.
Stars: ✭ 24 (+71.43%)
Mutual labels:  quote
htmlspecialchars
Escape special characters to HTML entities in JavaScript
Stars: ✭ 62 (+342.86%)
Mutual labels:  escape
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (+392.86%)
Mutual labels:  escape
laminas-escaper
Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs
Stars: ✭ 157 (+1021.43%)
Mutual labels:  escaping
jsonfiddle
JSON Fiddling
Stars: ✭ 14 (+0%)
Mutual labels:  escape

Build Status NPM Version

NAME

shell-escape-tag - an ES6 template tag which escapes parameters for interpolation into shell commands

INSTALL

$ npm install shell-escape-tag

SYNOPSIS

import shell from 'shell-escape-tag'

let filenames = glob('Holiday Snaps/*.jpg')
let title     = 'Holiday Snaps'
let command   = shell`compress --title ${title} ${filenames}`

console.log(command) // compress --title 'Holiday Snaps' 'Holiday Snaps/Pic 1.jpg' 'Holiday Snaps/Pic 2.jpg'

DESCRIPTION

This module exports an ES6 tagged-template function which escapes (i.e. quotes) its parameters for safe inclusion in shell commands. Parameters can be strings, arrays of strings, or nested arrays of strings, arrays and already-processed parameters.

The exported function also provides two helper functions which respectively escape and preserve their parameters and protect them from further processing.

EXPORTS

shell (default)

Signature: (template: string) → string

import shell from 'shell-escape-tag'

let filenames = ['foo bar', "baz's quux"]
let title     = 'My Title'
let command   = shell`command --title ${title} ${filenames}`

console.log(command) // command --title 'My Title' 'foo bar' 'baz'"'"'s quux'

Takes a template literal and escapes any interpolated parameters. null and undefined values are ignored. Arrays are flattened and their elements are escaped and joined with a space. All other values are stringified i.e. false is mapped to "false" etc. Parameters that have been escaped with shell.escape or preserved with shell.preserve are passed through verbatim.

FUNCTIONS

shell.escape

Signature: (...args: any[]) → object

import shell from 'shell-escape-tag'

let escaped = shell.escape("foo's bar")
let command1 = `command ${escaped}`
let command2 = shell`command ${escaped}`

console.log(command1) // command 'foo'"'"'s bar'
console.log(command2) // command 'foo'"'"'s bar'

Flattens, compacts and escapes any parameters which haven't already been escaped or preserved, joins the resulting elements with a space, and wraps the resulting string in an object which remains escaped when embedded in a template or passed as a direct or nested parameter to shell, shell.escape, or shell.preserve.

shell.preserve

Aliases: protect, verbatim

Signature: (...args: any[]) → object

import shell from 'shell-escape-tag'

let preserved = shell.preserve("baz's quux")
let command1 = `command "${preserved}"`
let command2 = shell`command "${preserved}"`

console.log(command1) // command "baz's quux"
console.log(command2) // command "baz's quux"

Flattens, compacts and preserves any parameters which haven't already been escaped or preserved, joins the resulting elements with a space, and wraps the resulting string in an object which is passed through verbatim when embedded in a template or passed as a direct or nested parameter to shell, shell.escape, or shell.preserve.

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • build - compile the code and save it to the dist directory
  • build:doc - generate the README's TOC (table of contents)
  • clean - remove the dist directory and other build artifacts
  • rebuild - clean the build artifacts and recompile the code
  • test - clean and rebuild and run the test suite
  • test:run - run the test suite

COMPATIBILITY

SEE ALSO

  • any-shell-escape - escape and stringify an array of arguments to be executed on the shell
  • execa - a better child_process
  • @perl/qw - a template tag for quoted word literals like Perl's qw(...)
  • @perl/qx - a template tag to run a command and capture its output like Perl's qx(...)
  • puka - a cross-platform library for safely passing strings through shells

VERSION

2.0.2

AUTHOR

chocolateboy

COPYRIGHT AND LICENSE

Copyright © 2015-2020 by chocolateboy.

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].