argv-flags 0.1.0 → 0.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.
Files changed (2) hide show
  1. package/index.js +26 -24
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -1,41 +1,43 @@
1
1
  function parseFlag ( targetArgument, argumentType ) {
2
2
  const processArguments = process.argv;
3
- let argsIndex = [];
4
3
 
5
- for ( const key in processArguments ) {
6
- if ( processArguments[key].charAt( 0 ) === '-' && processArguments[key].charAt( 0 ) === '-' ) {
7
- argsIndex.push( [ processArguments[key], key ] );
8
- }
9
- }
4
+ if ( processArguments.includes( targetArgument ) ) {
10
5
 
11
- for ( const key in processArguments ) {
12
- if ( argumentType === 'string' && processArguments[key] === targetArgument ) {
13
- return processArguments[Number( key ) + 1];
6
+ if ( argumentType === 'string' ) {
7
+ return processArguments[processArguments.indexOf( targetArgument ) + 1];
14
8
  }
9
+
10
+ if ( argumentType === 'array' ) {
11
+
12
+ let flagsIndex = [];
13
+
14
+ for ( const key in processArguments ) {
15
+ if ( processArguments[key].charAt( 0 ) === '-' && processArguments[key].charAt( 0 ) === '-' ) {
16
+ flagsIndex.push( [ processArguments[key], key ] );
17
+ }
18
+ }
15
19
 
16
- if ( argumentType === 'array' && processArguments[key] === targetArgument ) {
17
- for ( const key in argsIndex ) {
18
- if ( argsIndex[key][0] === targetArgument ) {
19
- if ( argsIndex[key][1] > argsIndex[argsIndex.length - 1][1] ) {
20
- return processArguments.slice( Number( argsIndex[key][1] ) + 1, argsIndex[Number( key ) + 1][1] );
20
+ for ( const key in flagsIndex ) {
21
+ if ( flagsIndex[key][0] === targetArgument ) {
22
+ if ( flagsIndex[key][1] < flagsIndex[flagsIndex.length - 1][1] ) {
23
+ return processArguments.slice( Number( flagsIndex[key][1] ) + 1, flagsIndex[Number( key ) + 1][1] );
21
24
  } else {
22
- return processArguments.slice( Number( argsIndex[key][1] ) + 1 );
25
+ return processArguments.slice( Number( flagsIndex[key][1] ) + 1 );
23
26
  }
24
27
  }
25
28
  }
26
29
  }
27
-
30
+
28
31
  if ( argumentType === 'boolean' ) {
29
- if ( processArguments.indexOf( targetArgument ) !== -1 ) {
30
- return true;
31
- }
32
- return false;
32
+ return true;
33
33
  }
34
-
35
- if ( argumentType === 'number' && processArguments[key] === targetArgument ) {
36
- return Number( processArguments[Number( key ) + 1] );
34
+
35
+ if ( argumentType === 'number' ) {
36
+ return Number( processArguments[processArguments.indexOf( targetArgument ) + 1] );
37
37
  }
38
38
  }
39
+
40
+ return false;
39
41
  }
40
42
 
41
- export { parseFlag };
43
+ module.exports = parseFlag;
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "argv-flags",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "type": "module",
7
6
  "scripts": {
8
7
  "test": "echo \"Error: no test specified\" && exit 1"
9
8
  },