Skip to content

Commit 15f42c1

Browse files
Correct JSDoc for stateless escapeAll and quoteAll (#2387)
Correct the description in the JSDoc for `escapeAll` and `quoteAll` in the stateless module. It incorrectly stated that non-array inputs are converted to one-element arrays (which was the behavior in v1 of this library). It now states that these are rejected explicitly, which has been added to the stateful variants' documentation too for clarity. Additionally, the stateless functions now have the `@throws` tag for non-array inputs causing an error.
1 parent 0a0150f commit 15f42c1

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export class Shescape {
118118
* Take an array of values, the arguments, and escape any dangerous characters
119119
* in every argument.
120120
*
121-
* Non-string inputs will be converted to strings using a `toString()` method.
121+
* Non-array inputs are rejected. Non-string entries will be converted to
122+
* strings using a `toString()` method.
122123
*
123124
* @param {string[]} args The arguments to escape.
124125
* @returns {string[]} The escaped arguments.
@@ -152,7 +153,8 @@ export class Shescape {
152153
* Take an array of values, the arguments, put shell-specific quotes around
153154
* every argument and escape any dangerous characters in every argument.
154155
*
155-
* Non-string inputs will be converted to strings using a `toString()` method.
156+
* Non-array inputs are rejected. Non-string entries will be converted to
157+
* strings using a `toString()` method.
156158
*
157159
* @param {string[]} args The arguments to quote and escape.
158160
* @returns {string[]} The quoted and escaped arguments.

src/stateless.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export function escape(arg, options) {
3636
* Take an array of values, the arguments, and escape any dangerous characters
3737
* in every argument.
3838
*
39-
* Non-array inputs will be converted to one-value arrays and non-string values
40-
* will be converted to strings using a `toString()` method.
39+
* Non-array inputs are rejected. Non-string entries will be converted to
40+
* strings using a `toString()` method.
4141
*
4242
* @example
4343
* import { spawn } from "node:child_process";
@@ -51,6 +51,7 @@ export function escape(arg, options) {
5151
* @param {boolean} [options.flagProtection=true] Is flag protection enabled.
5252
* @param {boolean | string} [options.shell=true] The shell to escape for.
5353
* @returns {string[]} The escaped arguments.
54+
* @throws {TypeError} The arguments are not an array.
5455
* @throws {TypeError} One of the arguments is not stringable.
5556
* @throws {Error} The shell is not supported or could not be found.
5657
* @since 2.1.0
@@ -93,8 +94,8 @@ export function quote(arg, options) {
9394
* Take an array of values, the arguments, put shell-specific quotes around
9495
* every argument and escape any dangerous characters in every argument.
9596
*
96-
* Non-array inputs will be converted to one-value arrays and non-string
97-
* values will be converted to strings using a `toString()` method.
97+
* Non-array inputs are rejected. Non-string entries will be converted to
98+
* strings using a `toString()` method.
9899
*
99100
* @example
100101
* import { spawn } from "node:child_process";
@@ -109,6 +110,7 @@ export function quote(arg, options) {
109110
* @param {boolean} [options.flagProtection=true] Is flag protection enabled.
110111
* @param {boolean | string} [options.shell=true] The shell to escape for.
111112
* @returns {string[]} The quoted and escaped arguments.
113+
* @throws {TypeError} The arguments are not an array.
112114
* @throws {TypeError} One of the arguments is not stringable.
113115
* @throws {Error} The shell is not supported or could not be found.
114116
* @throws {Error} Quoting is not supported with `shell: false`.

0 commit comments

Comments
 (0)