argv2object 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -9
- package/index.cjs +15 -15
- package/index.mjs +15 -15
- package/package.json +2 -2
- package/src/argv2Object.mjs +2 -2
- package/src/functions.mjs +6 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ A utility function for converting command-line arguments to a key-value object.
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
8
|
- [Importing](#importing)
|
|
9
9
|
- [Usage](#usage)
|
|
10
|
+
- [Dual Module Support](#dual-module-support)
|
|
10
11
|
- [Examples](#examples)
|
|
11
12
|
- [Simple key-value pairs](#simple-key-value-pairs)
|
|
12
13
|
- [Unix-style command-line options](#unix-style-command-line-options)
|
|
@@ -61,34 +62,49 @@ console.log(args.name); // "John"
|
|
|
61
62
|
|
|
62
63
|
```
|
|
63
64
|
|
|
65
|
+
## Dual Module Support
|
|
66
|
+
|
|
67
|
+
This package supports both:
|
|
68
|
+
|
|
69
|
+
- ES Modules: `import argv2object from 'argv2object'`
|
|
70
|
+
- CommonJS: `const argv2object = require('argv2object')`
|
|
71
|
+
|
|
72
|
+
The architecture uses separate entry points while sharing the same implementation.
|
|
73
|
+
|
|
74
|
+
## System Requirements
|
|
75
|
+
|
|
76
|
+
- **Node.js 14+** (Recommended for full support)
|
|
77
|
+
- **Node.js 12.x** (Experimental support)
|
|
78
|
+
- **Versiones anteriores**: Use version 1.x of this package
|
|
79
|
+
|
|
64
80
|
## Examples
|
|
65
81
|
|
|
66
82
|
### Simple key-value pairs
|
|
67
83
|
|
|
68
84
|
```sh
|
|
69
85
|
# Command line input:
|
|
70
|
-
node script.js task=some-task name=John level=admin
|
|
86
|
+
node script.js task=some-task age=30 name=John level=admin
|
|
71
87
|
|
|
72
88
|
```
|
|
73
89
|
|
|
74
90
|
```js
|
|
75
91
|
const args = argv2Object();
|
|
76
92
|
console.log(args);
|
|
77
|
-
// Output: { name: 'John', age:
|
|
93
|
+
// Output: { name: 'John', age: 30, level: 'admin' }
|
|
78
94
|
```
|
|
79
95
|
|
|
80
96
|
### Unix-style command-line options
|
|
81
97
|
|
|
82
98
|
```sh
|
|
83
99
|
# Command line input:
|
|
84
|
-
node --watch script.js -h --name=John --is-admin
|
|
100
|
+
node --watch script.js -h --help --name=John --is-admin
|
|
85
101
|
|
|
86
102
|
```
|
|
87
103
|
|
|
88
104
|
```js
|
|
89
105
|
const args = argv2Object(true);
|
|
90
106
|
console.log(args);
|
|
91
|
-
// Output: { h: true, name: 'John', is_admin: true }
|
|
107
|
+
// Output: { h: true, help: true, name: 'John', is_admin: true }
|
|
92
108
|
```
|
|
93
109
|
|
|
94
110
|
## API
|
|
@@ -113,11 +129,12 @@ Returns an `Object` with keys and values corresponding to the provided arguments
|
|
|
113
129
|
|
|
114
130
|
Throws
|
|
115
131
|
|
|
116
|
-
| Type | Description
|
|
117
|
-
|
|
118
|
-
| `
|
|
119
|
-
| `Error`
|
|
120
|
-
| `Error`
|
|
132
|
+
| Type | Description |
|
|
133
|
+
|---------|-------------------------------------------------------------------------------------------------|
|
|
134
|
+
| `TypeError` | If `unixmode` is not of type `boolean`. |
|
|
135
|
+
| `Error` | If no arguments are provided from command line. |
|
|
136
|
+
| `Error` | If `unixmode` is `true` and an argument does not follow the Unix-style command-line format. |
|
|
137
|
+
| `Error` | If `unixmode` is `false` and an argument does not follow the "key=value" format. |
|
|
121
138
|
|
|
122
139
|
## Contributing
|
|
123
140
|
|
package/index.cjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @file Manages main entry point.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
7
|
-
/**
|
|
8
|
-
* The `argv2Object()` function, converts command-line arguments to a key-value
|
|
9
|
-
* object.
|
|
2
|
+
* @file Entry point for CommonJS consumers.
|
|
10
3
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* The format can be either simple key-value pairs (e.g. "key=value") or
|
|
14
|
-
* Unix-style command-line options (e.g. "-o --option=value").
|
|
4
|
+
* Provides compatibility layer for Node.js environments
|
|
5
|
+
* using CommonJS require() system.
|
|
15
6
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
7
|
+
* This wrapper adapts the ESM default export to CommonJS
|
|
8
|
+
* module.exports pattern.
|
|
9
|
+
*
|
|
10
|
+
* @module argv2object/cjs
|
|
11
|
+
* @see module:argv2Object
|
|
12
|
+
* @since 1.1.0
|
|
13
|
+
* @example
|
|
14
|
+
* // CJS Usage
|
|
15
|
+
* const argv2object = require('argv2object');
|
|
19
16
|
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT LOCAL MODULES
|
|
20
20
|
const argv2Object = require('#argv2Object');
|
|
21
21
|
|
|
22
22
|
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
package/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @file Manages main entry point.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
7
|
-
/**
|
|
8
|
-
* The `argv2Object()` function, converts command-line arguments to a key-value
|
|
9
|
-
* object.
|
|
2
|
+
* @file Entry point for ES Module consumers.
|
|
10
3
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* The format can be either simple key-value pairs (e.g. "key=value") or
|
|
14
|
-
* Unix-style command-line options (e.g. "-o --option=value").
|
|
4
|
+
* Provides the default export of argv2object functionality
|
|
5
|
+
* for modern JavaScript environments using ES Modules.
|
|
15
6
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
7
|
+
* This file re-exports the main functionality from the
|
|
8
|
+
* implementation module while maintaining ESM compatibility.
|
|
9
|
+
*
|
|
10
|
+
* @module argv2object/esm
|
|
11
|
+
* @see module:argv2Object
|
|
12
|
+
* @since 1.1.0
|
|
13
|
+
* @example
|
|
14
|
+
* // ESM Usage
|
|
15
|
+
* import argv2object from 'argv2object';
|
|
19
16
|
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT LOCAL MODULES
|
|
20
20
|
import argv2Object from '#argv2Object';
|
|
21
21
|
|
|
22
22
|
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "argv2object",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A utility function for converting command-line arguments to a key-value object.",
|
|
6
6
|
"keywords": [
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"prettier": "^2.8.8"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
|
-
"node": ">=
|
|
70
|
+
"node": ">=14.0.0"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/argv2Object.mjs
CHANGED
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
* arguments: simple key-value pairs (e.g. "key=value") and Unix-style
|
|
11
11
|
* command-line arguments (e.g. "-k value" or "--key=value").
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
14
|
-
* @version 1.0.0
|
|
13
|
+
* @version 1.1.0
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
17
16
|
* Simple key-value pairs
|
|
@@ -49,6 +48,7 @@ import { formatKey, convertValue } from '#functions';
|
|
|
49
48
|
* @function
|
|
50
49
|
* @param {boolean} [unixmode=false] - Whether to parse Unix-style command-line options, the default value is `false`.
|
|
51
50
|
* @returns {ArgvObject} Returns an object with keys and values corresponding to the provided arguments.
|
|
51
|
+
* @throws {TypeError} If `unixmode` is not is not of type `boolean`.
|
|
52
52
|
* @throws {Error} If no arguments are provided from command line.
|
|
53
53
|
* @throws {Error} If `unixmode` is `true` and argument does not follow Unix-style command-line format.
|
|
54
54
|
* @throws {Error} If `unixmode` is `false` and argument does not follow 'key=value' format.
|
package/src/functions.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file Module containing utility functions for argument processing.
|
|
3
|
+
*
|
|
4
|
+
* Provides formatting and type conversion functions used internally
|
|
5
|
+
* by the argv2object library to normalize and transform command-line
|
|
6
|
+
* arguments into consistent JavaScript data structures.
|
|
3
7
|
*
|
|
4
8
|
* @module Functions
|
|
9
|
+
* @since 1.0.0
|
|
5
10
|
*/
|
|
6
11
|
|
|
7
12
|
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|