Comparing version 1.0.1 to 1.0.2
@@ -8,2 +8,11 @@ "use strict"; | ||
/** | ||
* @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) => { | ||
@@ -25,4 +34,36 @@ const re = new RegExp(`-(${short}|-${long})`); | ||
}; | ||
/** | ||
* Parse the config and extract arguments from the `process.argv` array. | ||
* @param {Config} config The configuration for parsing, where each key is a flag and values are either strings, or objects with possible properties: | ||
* | ||
* - __short__ Shorthand for this flag, 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`. | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* 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, | ||
* }, | ||
* } | ||
* ``` | ||
* | ||
* @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. | ||
*/ | ||
var _default = (config = {}, args = []) => { | ||
const argufy = (config = {}, args = []) => { | ||
const [,, ...argv] = args; | ||
@@ -57,7 +98,9 @@ /** @type {string} */ | ||
}; | ||
}, {}); | ||
}, {}); // /** @type {Object} */ | ||
return res; | ||
}; | ||
var _default = argufy; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
## 11 June 2018 | ||
### 1.0.2 | ||
- [doc] jsdoc documentation for `argufy`. | ||
## 11 June 2018 | ||
## 1.0.1 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "argufy", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Parse command line arguments to Node.js CLI programs.", | ||
@@ -5,0 +5,0 @@ "main": "build", |
@@ -0,1 +1,12 @@ | ||
/** | ||
* @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) => { | ||
@@ -16,3 +27,34 @@ const re = new RegExp(`-(${short}|-${long})`) | ||
export default (config = {}, args = []) => { | ||
/** | ||
* Parse the config and extract arguments from the `process.argv` array. | ||
* @param {Config} config The configuration for parsing, where each key is a flag and values are either strings, or objects with possible properties: | ||
* | ||
* - __short__ Shorthand for this flag, 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`. | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* 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, | ||
* }, | ||
* } | ||
* ``` | ||
* | ||
* @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. | ||
*/ | ||
const argufy = (config = {}, args = []) => { | ||
const [ ,, ...argv ] = args | ||
@@ -38,3 +80,6 @@ /** @type {string} */ | ||
}, {}) | ||
// /** @type {Object} */ | ||
return res | ||
} | ||
export default argufy |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17891
16
327