Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "validate" vs "validator" name issue in docs #407

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

th317erd
Copy link
Contributor

@th317erd th317erd commented Dec 1, 2023

Hello there!

When trying to use prompts, and copy + pasting from your own documentation, I ran into an exception thrown deep inside the prompts library:

Using your exact first example (or almost exact... I am using native ES6 modules):

import prompts from 'prompts';

(async () => {
  const response = await prompts({
    type: 'number',
    name: 'value',
    message: 'How old are you?',
    validate: value => value < 18 ? `Nightclub is 18+ only` : true
  });

  console.log(response); // => { value: 24 }
})();

This is the result:

? How old are you? › 23
    let valid = await this.validator(this.value);
                           ^

TypeError: this.validator is not a function
    at NumberPrompt.validate (.../node_modules/prompts/lib/elements/number.js:97:28)
    at NumberPrompt.submit (.../node_modules/prompts/lib/elements/number.js:106:16)
    at ReadStream.keypress (.../node_modules/prompts/lib/elements/prompt.js:32:16)
    at ReadStream.emit (node:events:515:28)
    at emitKeys (node:internal/readline/utils:371:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36)
    at ReadStream.emit (node:events:527:35)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)

Node.js v21.1.0

When I instead change the key to validator (vs validate as shown in the example) then everything works fine.

All tests are passing, so I made the assumption that it was the documentation that was wrong. If this assumption is incorrect please let me know. I find it odd that this has been around for 5 years without being reported? Is that correct? It concerns me that maybe I am missing context here.

Anyhow, I hope this helps. Accept or reject. I am just trying to help. :)

@terkelg terkelg merged commit 1a4ac9b into terkelg:master Dec 4, 2023
terkelg added a commit that referenced this pull request Dec 4, 2023
terkelg added a commit that referenced this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants