{ "name": "promptly", "version": "0.2.0", "description": "Simple command line prompting utility", "main": "index.js", "dependencies": { "read": "~1.0.4" }, "devDependencies": { "mocha": "~1.8.1", "async": "~0.1.22", "expect.js": "~0.2.0" }, "scripts": { "test": "mocha -R spec" }, "repository": { "type": "git", "url": "git://github.com/IndigoUnited/node-promptly" }, "bugs": { "url": "http://github.com/IndigoUnited/node-promptly/issues" }, "keywords": [ "prompt", "choose", "choice", "cli", "command", "line" ], "author": { "name": "IndigoUnited", "email": "hello@indigounited.com", "url": "http://indigounited.com" }, "license": "MIT", "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", "readmeFilename": "README.md", "homepage": "https://github.com/IndigoUnited/node-promptly", "_id": "promptly@0.2.0", "_shasum": "73ef200fa8329d5d3a8df41798950b8646ca46d9", "_from": "promptly@0.2.0", "_resolved": "https://registry.npmjs.org/promptly/-/promptly-0.2.0.tgz" }