Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Removes an extra space in the prompt, adds the default
message
, and fixes the logic to match the Deno implementation.I compared it to https://github.com/denoland/deno/blob/main/runtime/js/41_prompt.js#L33-L50, correct me if this is the wrong place please!
The main part of the Deno implementation looks like this:
https://github.com/denoland/deno/blob/a4ec7dfae01485290af91c62c1ce17a742dcb104/runtime/js/41_prompt.js#L34-L44
defaultValue
is assigned tonull
ifdefaultValue
isundefined
ornull
(see nullish coalescing assignment (??=)). Then, ifdefaultValue
is truthy,[${defaultValue}]
is added tomessage
.I'll admit I'm quite confused why the
defaultValue ??= null;
line is needed; bothnull
andundefined
are not truthy soo theif (defaultValue) {
part works the same either way...Anyway, the logic for this shim implementation used to look like this:
https://github.com/denoland/node_shims/blob/main/packages/shim-prompts/src/index.ts#L35
Which, if expanded to an if statement and rearranged, would look like this:
Because the
defaultValue ??= null;
line is not needed (see above), the difference isdefaultValue != null
in the shim vsdefaultValue
in the Deno version. Hence, I've changed it to be accurate, just checking ifdefaultValue
is truthy rather than if it equalsnull
.