package.json 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. {
  2. "name": "promptly",
  3. "version": "0.2.0",
  4. "description": "Simple command line prompting utility",
  5. "main": "index.js",
  6. "dependencies": {
  7. "read": "~1.0.4"
  8. },
  9. "devDependencies": {
  10. "mocha": "~1.8.1",
  11. "async": "~0.1.22",
  12. "expect.js": "~0.2.0"
  13. },
  14. "scripts": {
  15. "test": "mocha -R spec"
  16. },
  17. "repository": {
  18. "type": "git",
  19. "url": "git://github.com/IndigoUnited/node-promptly"
  20. },
  21. "bugs": {
  22. "url": "http://github.com/IndigoUnited/node-promptly/issues"
  23. },
  24. "keywords": [
  25. "prompt",
  26. "choose",
  27. "choice",
  28. "cli",
  29. "command",
  30. "line"
  31. ],
  32. "author": {
  33. "name": "IndigoUnited",
  34. "email": "hello@indigounited.com",
  35. "url": "http://indigounited.com"
  36. },
  37. "license": "MIT",
  38. "readme": "# promptly\n\n[![Build Status](https://secure.travis-ci.org/IndigoUnited/node-promptly.png)](http://travis-ci.org/IndigoUnited/node-promptly.png)\n\nSimple command line prompting utility.\n\n## Installation\n\n`$ npm install promptly`\n\n\n## API\n\n\nNote that the `options` argument is optional for all the commands.\n\n\n### .prompt(message, opts, fn)\n\nPrompts for a value, printing the `message` and waiting for the input. \nWhen done, calls `fn` with `error` and `value`.\n\nDefault options:\n```js\n{\n // The default value. If not supplied, the input is mandatory\n 'default': null,\n // Automatically trim the input\n 'trim': true,\n // A validator or an array of validators.\n 'validator': null,\n // Automatically retry if a validator fails\n 'retry': true,\n // Do not print what the user types\n 'silent': false,\n // Input and output streams to read and write to\n 'input': process.stdin,\n 'output': process.stdout\n}\n```\n\nThe validators have two purposes:\n```js\nfunction (value) {\n // Validation example, throwing an error when invalid\n if (value.length !== 2) {\n throw new Error('Length must be 2');\n }\n\n // Parse the value, modifying it\n return value.replace('aa', 'bb');\n}\n```\n\nExample usages\n\nAsk for a name:\n```js\npromptly.prompt('Name: ', function (err, value) {\n // err is always null in this case, because no validators are set\n console.log(value);\n});\n```\n\nAsk for a name with a constraint (non-empty value and length > 2):\n\n```js\nvar validator = function (value) {\n if (value.length < 2) {\n throw new Error('Min length of 2');\n }\n\n return value;\n};\n\npromptly.prompt('Name: ', { validator: validator }, function (err, value) {\n // Since retry is true by default, err is always null\n // because promptly will be prompting for a name until it validates\n // Between each prompt, the error message from the validator will be printed\n console.log('Name is:', value);\n});\n```\n\nSame as above but do not retry automatically:\n\n```js\nvar validator = function (value) {\n if (value.length < 2) {\n throw new Error('Min length of 2');\n }\n\n return value;\n};\n\npromptly.prompt('Name: ', { validator: validator, retry: false }, function (err, value) {\n if (err) {\n console.error('Invalid name:', e.message);\n // Manually call retry\n // The passed error has a retry method to easily prompt again.\n return err.retry();\n }\n\n console.log('Name is:', value);\n});\n```\n\n### .confirm(message, opts, fn)\n\nAsk the user to confirm something. \nCalls `fn` with `error` and `value` (true or false).\n\nTruthy values are: `y`, `yes` and `1`. \nFalsy values are `n`, `no`, and `0`. \nComparison is made in a case insensitive way.\n\nExample usage:\n\n```js\npromptly.confirm('Are you sure? ', function (err, value) {\n console.log('Answer:', value);\n});\n```\n\n\n### .choose(message, choices, opts, fn)\n\nAsk the user to choose between multiple `choices` (array of choices). \nCalls `fn` with `error` and `value`.\n\nExample usage:\n\n```js\npromptly.choose('Do you want an apple or an orange? ', ['apple', 'orange'], function (err, value) {\n console.log('Answer:', value);\n});\n```\n\n\n### .password(message, opts, fn)\n\nPrompts for a password, printing the `message` and waiting for the input. \nWhen available, calls `fn` with `error` and `value`.\n\nThe available options are the same, except that `trim` and `silent` default to `false` and `default` is an empty string (to allow empty passwords).\n\nExample usage:\n\n```js\npromptly.password('Type a password: ', function (err, value) {\n console.log('Password is:', value);\n});\n```\n\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n",
  39. "readmeFilename": "README.md",
  40. "homepage": "https://github.com/IndigoUnited/node-promptly",
  41. "_id": "promptly@0.2.0",
  42. "_shasum": "73ef200fa8329d5d3a8df41798950b8646ca46d9",
  43. "_from": "promptly@0.2.0",
  44. "_resolved": "https://registry.npmjs.org/promptly/-/promptly-0.2.0.tgz"
  45. }