Comparing version
@@ -6,13 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.default = argufy; | ||
/** | ||
* @typedef {Object} Flag | ||
* @property {string} [short] Shorthand for this flag, usually one letter. | ||
* @property {boolean} [boolean] Does not have to be followed by a value, true if given. | ||
* @property {boolean} [number] Parse as a number. | ||
* @property {boolean} [command] Whether this flag can be specified as the first argument without the dash, such as `example run`: run is the command. | ||
* | ||
* @typedef {Object.<string, string|Flag>} Config | ||
*/ | ||
const find = (argv, long, short, bool, number) => { | ||
@@ -38,6 +29,7 @@ const re = new RegExp(`-(${short}|-${long})`); | ||
* | ||
* - __short__ Shorthand for this flag, usually one letter. | ||
* - __short__ Shorthand for this argument, usually one letter. | ||
* - __boolean__ Does not have to be followed by a value, true if given. | ||
* - __number__ Parse as a number. | ||
* - __command__ Whether this flag can be specified as the first argument without the dash, such as `example run`. | ||
* - __command__ Whether this argument can be specified as the first argument without the dash, such as `example run`. | ||
* - __multiple__ Extract multiple commands as an array when `command` is set to true. | ||
* | ||
@@ -47,22 +39,26 @@ * @example | ||
* const config = { | ||
* title: 't', // program -t Title | ||
* open: { // program -o | ||
* short: 'o', | ||
* boolean: true, | ||
* }, | ||
* delay: { // program -d 100 | ||
* short: 'd', | ||
* number: true, | ||
* }, | ||
* file: { // program File.txt | ||
* command: true, | ||
* }, | ||
* title: 't', // program -t Title | ||
* open: { // program -o | ||
* short: 'o', | ||
* boolean: true, | ||
* }, | ||
* delay: { // program -d 100 | ||
* short: 'd', | ||
* number: true, | ||
* }, | ||
* file: { // program File.txt | ||
* command: true, | ||
* }, | ||
* file2: { // program File.txt File2.txt | ||
* command: true, | ||
* multiple: true, | ||
* }, | ||
* } | ||
* | ||
* @param {string[]} args value of process.argv. It is assumed that user arguments start from the 3rd position. | ||
* @returns {Object.<string, string|boolean|number>} An object with all found values for the configuration request. | ||
* @param {string[]} [args] Array with arguments to parse. `process.argv` is used by default. It is assumed that user arguments start from the 3rd position. | ||
* @returns {Object.<string, string|string[]|boolean|number>} An object with all found values for the configuration request. | ||
*/ | ||
const argufy = (config = {}, args = process.argv) => { | ||
function argufy(config = {}, args = process.argv) { | ||
const [,, ...argv] = args; | ||
@@ -106,3 +102,3 @@ /** @type {string} */ | ||
return res; | ||
}; | ||
} | ||
@@ -120,5 +116,12 @@ const findTitles = argv => { | ||
}; | ||
var _default = argufy; | ||
exports.default = _default; | ||
/** | ||
* @typedef {Object} Flag | ||
* @property {string} [short] Shorthand for this argument, usually one letter. | ||
* @property {boolean} [boolean] Does not have to be followed by a value, true if given. | ||
* @property {boolean} [number] Parse as a number. | ||
* @property {boolean} [command] Whether this argument can be specified as the first argument without the dash, such as `example run`: run is the command. | ||
* @property {boolean} [multiple] Extract multiple commands as an array when `command` is set to true. | ||
* | ||
* @typedef {Object.<string, string|Flag>} Config | ||
*/ | ||
//# sourceMappingURL=index.js.map |
## 15 June 2018 | ||
### 1.1.1 | ||
- [doc] jsdoc | ||
### 1.1.0 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "argufy", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Parse command line arguments to Node.js CLI programs.", | ||
@@ -5,0 +5,0 @@ "main": "build", |
@@ -1,12 +0,1 @@ | ||
/** | ||
* @typedef {Object} Flag | ||
* @property {string} [short] Shorthand for this flag, usually one letter. | ||
* @property {boolean} [boolean] Does not have to be followed by a value, true if given. | ||
* @property {boolean} [number] Parse as a number. | ||
* @property {boolean} [command] Whether this flag can be specified as the first argument without the dash, such as `example run`: run is the command. | ||
* | ||
* @typedef {Object.<string, string|Flag>} Config | ||
*/ | ||
const find = (argv, long, short, bool, number) => { | ||
@@ -31,6 +20,7 @@ const re = new RegExp(`-(${short}|-${long})`) | ||
* | ||
* - __short__ Shorthand for this flag, usually one letter. | ||
* - __short__ Shorthand for this argument, usually one letter. | ||
* - __boolean__ Does not have to be followed by a value, true if given. | ||
* - __number__ Parse as a number. | ||
* - __command__ Whether this flag can be specified as the first argument without the dash, such as `example run`. | ||
* - __command__ Whether this argument can be specified as the first argument without the dash, such as `example run`. | ||
* - __multiple__ Extract multiple commands as an array when `command` is set to true. | ||
* | ||
@@ -40,20 +30,24 @@ * @example | ||
* const config = { | ||
* title: 't', // program -t Title | ||
* open: { // program -o | ||
* short: 'o', | ||
* boolean: true, | ||
* }, | ||
* delay: { // program -d 100 | ||
* short: 'd', | ||
* number: true, | ||
* }, | ||
* file: { // program File.txt | ||
* command: true, | ||
* }, | ||
* title: 't', // program -t Title | ||
* open: { // program -o | ||
* short: 'o', | ||
* boolean: true, | ||
* }, | ||
* delay: { // program -d 100 | ||
* short: 'd', | ||
* number: true, | ||
* }, | ||
* file: { // program File.txt | ||
* command: true, | ||
* }, | ||
* file2: { // program File.txt File2.txt | ||
* command: true, | ||
* multiple: true, | ||
* }, | ||
* } | ||
* | ||
* @param {string[]} args value of process.argv. It is assumed that user arguments start from the 3rd position. | ||
* @returns {Object.<string, string|boolean|number>} An object with all found values for the configuration request. | ||
* @param {string[]} [args] Array with arguments to parse. `process.argv` is used by default. It is assumed that user arguments start from the 3rd position. | ||
* @returns {Object.<string, string|string[]|boolean|number>} An object with all found values for the configuration request. | ||
*/ | ||
const argufy = (config = {}, args = process.argv) => { | ||
export default function argufy(config = {}, args = process.argv) { | ||
const [ ,, ...argv ] = args | ||
@@ -97,2 +91,11 @@ /** @type {string} */ | ||
export default argufy | ||
/** | ||
* @typedef {Object} Flag | ||
* @property {string} [short] Shorthand for this argument, usually one letter. | ||
* @property {boolean} [boolean] Does not have to be followed by a value, true if given. | ||
* @property {boolean} [number] Parse as a number. | ||
* @property {boolean} [command] Whether this argument can be specified as the first argument without the dash, such as `example run`: run is the command. | ||
* @property {boolean} [multiple] Extract multiple commands as an array when `command` is set to true. | ||
* | ||
* @typedef {Object.<string, string|Flag>} Config | ||
*/ |
Sorry, the diff of this file is not supported yet
22084
4.7%375
2.46%