+5
-0
@@ -12,2 +12,7 @@ # Changelog | ||
| ## [0.3.0] - 2020-12-07 | ||
| - Add `escape` function to escape an argument (same as `shescape()`). | ||
| - Add `quote` function to quote and escape an argument. | ||
| ## [0.2.1] - 2020-11-07 | ||
@@ -14,0 +19,0 @@ |
+10
-0
@@ -9,1 +9,11 @@ const os = require("os"); | ||
| }; | ||
| module.exports.escape = function (arg) { | ||
| const platform = os.platform(); | ||
| return main.escapeShellArgByPlatform(arg, platform); | ||
| }; | ||
| module.exports.quote = function (arg) { | ||
| const platform = os.platform(); | ||
| return main.quoteByPlatform(arg, platform); | ||
| }; |
+7
-2
| { | ||
| "name": "shescape", | ||
| "version": "0.2.1", | ||
| "version": "0.3.0", | ||
| "description": "simple shell escape library", | ||
@@ -11,2 +11,5 @@ "homepage": "https://github.com/ericcornelissen/shescape#readme", | ||
| "lint": "prettier --check ./**/*.{js,md,yml}", | ||
| "_postinstall": "is-ci || husky install", | ||
| "prepublishOnly": "pinst --disable", | ||
| "postpublish": "pinst --enable", | ||
| "test": "mocha" | ||
@@ -32,4 +35,6 @@ }, | ||
| "devDependencies": { | ||
| "husky": "^4.3.0", | ||
| "husky": "^5.0.4", | ||
| "is-ci": "^2.0.0", | ||
| "mocha": "^8.2.0", | ||
| "pinst": "^2.1.1", | ||
| "prettier": "^2.1.2", | ||
@@ -36,0 +41,0 @@ "sinon": "^9.2.1" |
+4
-3
@@ -11,4 +11,5 @@ # Shescape | ||
| Below is an example of how to use _Shescape_. Note that you must call _Shescape_ | ||
| only on the user input, and put the output in between single quotes. | ||
| Below is a basic example of how to use _Shescape_. It is recommended to use the | ||
| `quote` function. This will put (OS appropriate) quotes around the user input | ||
| and escape any characters in the input if necessary. | ||
@@ -19,3 +20,3 @@ ```js | ||
| cp.exec(`command '${shescape(userInput)}'`, callback); | ||
| cp.exec(`command ${shescape.quote(userInput)}`, callback); | ||
| ``` | ||
@@ -22,0 +23,0 @@ |
+11
-0
@@ -14,2 +14,13 @@ const { win32 } = require("./constants.js"); | ||
| function quoteByPlatform(arg, platform) { | ||
| const safeArg = escapeShellArgByPlatform(arg, platform); | ||
| switch (platform) { | ||
| case win32: | ||
| return `"${safeArg}"`; | ||
| default: | ||
| return `'${safeArg}'`; | ||
| } | ||
| } | ||
| module.exports.escapeShellArgByPlatform = escapeShellArgByPlatform; | ||
| module.exports.quoteByPlatform = quoteByPlatform; |
21777
4.37%45
66.67%27
3.85%6
50%