ArgvArray

@alexeyp0708/argv_patterns. ArgvArray

Class ArgvArray create array containing [object ArgvElement]

Constructor

new ArgvArray(…args) → {Array.<ArgvElement>}

Creates an array of [object ArgvElement] elements based on the command line, or an array of Argv parameters

Source:
Parameters:
Name Type Attributes Description
args string | object <repeatable>

args[0] string|Array - command line or Array from argv params, or arvs - argv array

Returns:
Type:
Array.<ArgvElement>
Example
var result=new ArgvArray('command --option -o=value');
var result=new ArgvArray(['command','--option','-o=value']);
var result= new ArgvArray('command','--option','-o=value');

```
//result
[
   "[object ArgvElement]",
   "[object ArgvElement]",
   "[object ArgvElement]"
]
```
var result= new ArgvArray([['command','--option'],[['command2','--option2'],['command3','--option3']]]);
//equivalent to
var result= new ArgvArray('command','--option','command2','--option2','command3','--option3');

Members

(static) elementClass :ArgvElement

Using this property, you can replace the class [object ArgvElement] the advanced class If ArgvArray.elementClass = null, then [class ArgvElement] will be set by default

Source:
Type:
  • ArgvElement
Example
class ExtArgvElement extends ArgvElement {}
ArgvArray.elementClass=ExtArgvElement;
let argv=new ArgvArray('command --option');
argv[0] instanceof ExtArgvElement // true

(static) elementClass :ArgvElement

Using this property, you can replace the class [object ArgvElement] the advanced class If ArgvArray.elementClass = null, then [class ArgvElement] will be set by default

Source:
Type:
  • ArgvElement
Example
class ExtArgvElement extends ArgvElement {}
ArgvArray.elementClass=ExtArgvElement;
let argv=new ArgvArray('command --option');
argv[0] instanceof ExtArgvElement // true

Methods

(static) elementsToArray(argv) → {Array.<string>}

Converting [object ArgvElement] elements from [array ArgvArray] to string parameters array

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
Array.<string>

(static) elementsToArray(argv) → {Array.<string>}

Converting [object ArgvElement] elements from [array ArgvArray] to string parameters array

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
Array.<string>

(static) elementsToString(argv) → {string}

Converting [object ArgvElement] elements from [array ArgvArray] to command line

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
string

(static) elementsToString(argv) → {string}

Converting [object ArgvElement] elements from [array ArgvArray] to command line

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
string

(static) parse(argv) → {Array}

Parses the command line or argv parameter array and returns an [array ArgvArray].

Source:
Parameters:
Name Type Description
argv Array.<string> | Array.<array> | string

Array type- argv parameters set. String type -parameters command line. If an array element is an array, then this array is considered to be a set of command parameters and all its elements will be embedded in the existing array set. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Throws:

Error: Bad parameters - syntactically bad parameter or poorly constructed command line

Returns:
Type:
Array

A collection of [object ArgvElement]

(static) parse(argv) → {Array}

Parses the command line or argv parameter array and returns an [array ArgvArray].

Source:
Parameters:
Name Type Description
argv Array.<string> | Array.<array> | string

Array type- argv parameters set. String type -parameters command line. If an array element is an array, then this array is considered to be a set of command parameters and all its elements will be embedded in the existing array set. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Throws:

Error: Bad parameters - syntactically bad parameter or poorly constructed command line

Returns:
Type:
Array

A collection of [object ArgvElement]

(static) parseCommand(str) → {Array.<string>}

Command line parse. Breaks the command line into argv parameters.

Source:
Parameters:
Name Type Description
str string

Command line. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Returns:
Type:
Array.<string>

Returns an argv-style array of parameters

Example
Argv.parseCommand('command1 --option -o=value "command2" --option2="value string"');
//result
[
     'command1',
     '--option',
     '-o=value',
     'command2',
     '--option2=value string'
];

(static) parseCommand(str) → {Array.<string>}

Command line parse. Breaks the command line into argv parameters.

Source:
Parameters:
Name Type Description
str string

Command line. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Returns:
Type:
Array.<string>

Returns an argv-style array of parameters

Example
Argv.parseCommand('command1 --option -o=value "command2" --option2="value string"');
//result
[
     'command1',
     '--option',
     '-o=value',
     'command2',
     '--option2=value string'
];

add(element, params) → {this}

Add a new parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

Where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the added element

params object | ArgvElement

if 1 argument is string, it is used as parameters setting for the element (template for [object ArgvElement])

Returns:
Type:
this
Example
let argv=new ArgvArray();
argv
     .add('command',{description:'test command'})
     .add('--option',{required:true})
     .add('-o=value');

add(element, params) → {this}

Add a new parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

Where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the added element

params object | ArgvElement

if 1 argument is string, it is used as parameters setting for the element (template for [object ArgvElement])

Returns:
Type:
this
Example
let argv=new ArgvArray();
argv
     .add('command',{description:'test command'})
     .add('--option',{required:true})
     .add('-o=value');

concat(…args) → {ArgvArray}

Same as Array.prototype.push, but converts the elements of the arguments (arrays) to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args Array.<Array> <repeatable>

converted to [object ArgvElement]

Returns:
Type:
ArgvArray

concat(…args) → {ArgvArray}

Same as Array.prototype.push, but converts the elements of the arguments (arrays) to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args Array.<Array> <repeatable>

converted to [object ArgvElement]

Returns:
Type:
ArgvArray

fill(value, start, end) → {Array}

Same as Array.prototype.fill, but converts argument 1 to [object ArgvElement]

Source:
Parameters:
Name Type Description
value

converted to [object ArgvElement]

start
end
Returns:
Type:
Array

fill(value, start, end) → {Array}

Same as Array.prototype.fill, but converts argument 1 to [object ArgvElement]

Source:
Parameters:
Name Type Description
value

converted to [object ArgvElement]

start
end
Returns:
Type:
Array

get(element, params) → {ArgvElement|boolean}

search argv element

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement). Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }
params object | ArgvElement

If 1 argument is string, this is set of element parameters (template for ArgvElement)

Returns:
Type:
ArgvElement | boolean

If false, then the item was not found. If found, it returns [object ArgvElement]

Example
let argv=new ArgvArray('command1 command2 --option1=value');
 argv.get('command2'); // result =>[object ArgvElement]
 argv.get('command2',{order:2});//result => [object ArgvElement]
 argv.get('command2',{order:1});//result => false
 argv.get('--option'); // result=>[object ArgvElement]
 argv.get('--option=value');// result=>[object ArgvElement]
 argv.get('--option=val');// result=>false

get(element, params) → {ArgvElement|boolean}

search argv element

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement). Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }
params object | ArgvElement

If 1 argument is string, this is set of element parameters (template for ArgvElement)

Returns:
Type:
ArgvElement | boolean

If false, then the item was not found. If found, it returns [object ArgvElement]

Example
let argv=new ArgvArray('command1 command2 --option1=value');
 argv.get('command2'); // result =>[object ArgvElement]
 argv.get('command2',{order:2});//result => [object ArgvElement]
 argv.get('command2',{order:1});//result => false
 argv.get('--option'); // result=>[object ArgvElement]
 argv.get('--option=value');// result=>[object ArgvElement]
 argv.get('--option=val');// result=>false

push(…args) → {number}

Same as Array.prototype.push, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

push(…args) → {number}

Same as Array.prototype.push, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

searchElement(element, isFirst) → {Array.<ArgvElement>}

search ArgvElement in ArgvArray by keys and/or value

Source:
Parameters:
Name Type Default Description
element ArgvElement | object | string

Sets the dataset to search

{
    type, // 
    key, // Data type =>  * | string | [object RegExp]
    value, // for {type:'option'}. data type =>  * | string | [object RegExp]
    order // for {type:'command'} 
}

or pattern string for element Example:"/command1|command2/", "[--option=value]"

isFirst boolean false

one result in array

Returns:
Type:
Array.<ArgvElement>

searchElement(element, isFirst) → {Array.<ArgvElement>}

search ArgvElement in ArgvArray by keys and/or value

Source:
Parameters:
Name Type Default Description
element ArgvElement | object | string

Sets the dataset to search

{
    type, // 
    key, // Data type =>  * | string | [object RegExp]
    value, // for {type:'option'}. data type =>  * | string | [object RegExp]
    order // for {type:'command'} 
}

or pattern string for element Example:"/command1|command2/", "[--option=value]"

isFirst boolean false

one result in array

Returns:
Type:
Array.<ArgvElement>

searchElements(elements, isFirst, isCommand) → {Array|ArgvArray}

search ArgvElements

Source:
Parameters:
Name Type Default Description
elements string | Array.<string> | ArgvArray | Array.<ArgvElement> | Array.<object>

string or strings array - commandline or parametrs set command line objects array - ArgvElement templates set

[
 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 },
 ...     *
]
isFirst boolean false

isFirst - one result in array

isCommand boolean false

if isCommand===true then returns [array ArgvArray]

Returns:
Type:
Array | ArgvArray

Array - if isFirst equal true, then return argvElement array.
If isFirst equal false, then return [[ArgvElement....],[...],[...]]. If isCommand===true then returns [array ArgvArray]

searchElements(elements, isFirst, isCommand) → {Array|ArgvArray}

search ArgvElements

Source:
Parameters:
Name Type Default Description
elements string | Array.<string> | ArgvArray | Array.<ArgvElement> | Array.<object>

string or strings array - commandline or parametrs set command line objects array - ArgvElement templates set

[
 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 },
 ...     *
]
isFirst boolean false

isFirst - one result in array

isCommand boolean false

if isCommand===true then returns [array ArgvArray]

Returns:
Type:
Array | ArgvArray

Array - if isFirst equal true, then return argvElement array.
If isFirst equal false, then return [[ArgvElement....],[...],[...]]. If isCommand===true then returns [array ArgvArray]

set(element, params) → {this}

Sets a new parameter or overwrites the properties of the specified parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for [object ArgvElement]) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the element

params object | ArgvElement

if 1 argument is string, it is used as parameter setting for the element (template for [object ArgvElement])

Returns:
Type:
this

set(element, params) → {this}

Sets a new parameter or overwrites the properties of the specified parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for [object ArgvElement]) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the element

params object | ArgvElement

if 1 argument is string, it is used as parameter setting for the element (template for [object ArgvElement])

Returns:
Type:
this

sort(call)

sorting items by order

Source:
Parameters:
Name Type Description
call

sort(call)

sorting items by order

Source:
Parameters:
Name Type Description
call

splice(start, deleteCount, …items) → {Array.<any>}

ame as Array.prototype.fill, but converts rest arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
start
deleteCount
items <repeatable>

converted to [object ArgvElement]

Returns:
Type:
Array.<any>

splice(start, deleteCount, …items) → {Array.<any>}

ame as Array.prototype.fill, but converts rest arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
start
deleteCount
items <repeatable>

converted to [object ArgvElement]

Returns:
Type:
Array.<any>

toArray() → {Array.<string>}

converts ArgvArray to Array

Source:
Returns:
Type:
Array.<string>

toArray() → {Array.<string>}

converts ArgvArray to Array

Source:
Returns:
Type:
Array.<string>

toElement(element) → {ArgvElement}

convert string or Array to [object ArgvElement]

Source:
Parameters:
Name Type Description
element string
Returns:
Type:
ArgvElement
Example
let argv=new ArgvArray();
let result= argv.toElement('command --option -o=value'); //[object ArgvElement]

toElement(element) → {ArgvElement}

convert string or Array to [object ArgvElement]

Source:
Parameters:
Name Type Description
element string
Returns:
Type:
ArgvElement
Example
let argv=new ArgvArray();
let result= argv.toElement('command --option -o=value'); //[object ArgvElement]

toString() → {string}

Converts ArgvArray to command line

Source:
Returns:
Type:
string

Command line

Example
let argv=new ArgvArray(['command', '--option', '-o value']);
argv.toString();
//result
//'command --option -o=value'

toString() → {string}

Converts ArgvArray to command line

Source:
Returns:
Type:
string

Command line

Example
let argv=new ArgvArray(['command', '--option', '-o value']);
argv.toString();
//result
//'command --option -o=value'

unshift(…args) → {number}

Same as Array.prototype.unshift, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

unshift(…args) → {number}

Same as Array.prototype.unshift, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

@alexeyp0708/argv_patterns. ArgvArray

Class ArgvArray create array containing [object ArgvElement]

Constructor

new ArgvArray(…args) → {Array.<ArgvElement>}

Creates an array of [object ArgvElement] elements based on the command line, or an array of Argv parameters

Source:
Parameters:
Name Type Attributes Description
args string | object <repeatable>

args[0] string|Array - command line or Array from argv params, or arvs - argv array

Returns:
Type:
Array.<ArgvElement>
Example
var result=new ArgvArray('command --option -o=value');
var result=new ArgvArray(['command','--option','-o=value']);
var result= new ArgvArray('command','--option','-o=value');

```
//result
[
   "[object ArgvElement]",
   "[object ArgvElement]",
   "[object ArgvElement]"
]
```
var result= new ArgvArray([['command','--option'],[['command2','--option2'],['command3','--option3']]]);
//equivalent to
var result= new ArgvArray('command','--option','command2','--option2','command3','--option3');

Members

(static) elementClass :ArgvElement

Using this property, you can replace the class [object ArgvElement] the advanced class If ArgvArray.elementClass = null, then [class ArgvElement] will be set by default

Source:
Type:
  • ArgvElement
Example
class ExtArgvElement extends ArgvElement {}
ArgvArray.elementClass=ExtArgvElement;
let argv=new ArgvArray('command --option');
argv[0] instanceof ExtArgvElement // true

(static) elementClass :ArgvElement

Using this property, you can replace the class [object ArgvElement] the advanced class If ArgvArray.elementClass = null, then [class ArgvElement] will be set by default

Source:
Type:
  • ArgvElement
Example
class ExtArgvElement extends ArgvElement {}
ArgvArray.elementClass=ExtArgvElement;
let argv=new ArgvArray('command --option');
argv[0] instanceof ExtArgvElement // true

Methods

(static) elementsToArray(argv) → {Array.<string>}

Converting [object ArgvElement] elements from [array ArgvArray] to string parameters array

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
Array.<string>

(static) elementsToArray(argv) → {Array.<string>}

Converting [object ArgvElement] elements from [array ArgvArray] to string parameters array

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
Array.<string>

(static) elementsToString(argv) → {string}

Converting [object ArgvElement] elements from [array ArgvArray] to command line

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
string

(static) elementsToString(argv) → {string}

Converting [object ArgvElement] elements from [array ArgvArray] to command line

Source:
Parameters:
Name Type Description
argv ArgvArray
Throws:

Error: Bad argument - Invalid argument

Returns:
Type:
string

(static) parse(argv) → {Array}

Parses the command line or argv parameter array and returns an [array ArgvArray].

Source:
Parameters:
Name Type Description
argv Array.<string> | Array.<array> | string

Array type- argv parameters set. String type -parameters command line. If an array element is an array, then this array is considered to be a set of command parameters and all its elements will be embedded in the existing array set. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Throws:

Error: Bad parameters - syntactically bad parameter or poorly constructed command line

Returns:
Type:
Array

A collection of [object ArgvElement]

(static) parse(argv) → {Array}

Parses the command line or argv parameter array and returns an [array ArgvArray].

Source:
Parameters:
Name Type Description
argv Array.<string> | Array.<array> | string

Array type- argv parameters set. String type -parameters command line. If an array element is an array, then this array is considered to be a set of command parameters and all its elements will be embedded in the existing array set. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Throws:

Error: Bad parameters - syntactically bad parameter or poorly constructed command line

Returns:
Type:
Array

A collection of [object ArgvElement]

(static) parseCommand(str) → {Array.<string>}

Command line parse. Breaks the command line into argv parameters.

Source:
Parameters:
Name Type Description
str string

Command line. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Returns:
Type:
Array.<string>

Returns an argv-style array of parameters

Example
Argv.parseCommand('command1 --option -o=value "command2" --option2="value string"');
//result
[
     'command1',
     '--option',
     '-o=value',
     'command2',
     '--option2=value string'
];

(static) parseCommand(str) → {Array.<string>}

Command line parse. Breaks the command line into argv parameters.

Source:
Parameters:
Name Type Description
str string

Command line. Warning: quotes ( " and ') inside quotes are not recognized when parsing a string.

Returns:
Type:
Array.<string>

Returns an argv-style array of parameters

Example
Argv.parseCommand('command1 --option -o=value "command2" --option2="value string"');
//result
[
     'command1',
     '--option',
     '-o=value',
     'command2',
     '--option2=value string'
];

add(element, params) → {this}

Add a new parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

Where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the added element

params object | ArgvElement

if 1 argument is string, it is used as parameters setting for the element (template for [object ArgvElement])

Returns:
Type:
this
Example
let argv=new ArgvArray();
argv
     .add('command',{description:'test command'})
     .add('--option',{required:true})
     .add('-o=value');

add(element, params) → {this}

Add a new parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

Where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the added element

params object | ArgvElement

if 1 argument is string, it is used as parameters setting for the element (template for [object ArgvElement])

Returns:
Type:
this
Example
let argv=new ArgvArray();
argv
     .add('command',{description:'test command'})
     .add('--option',{required:true})
     .add('-o=value');

concat(…args) → {ArgvArray}

Same as Array.prototype.push, but converts the elements of the arguments (arrays) to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args Array.<Array> <repeatable>

converted to [object ArgvElement]

Returns:
Type:
ArgvArray

concat(…args) → {ArgvArray}

Same as Array.prototype.push, but converts the elements of the arguments (arrays) to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args Array.<Array> <repeatable>

converted to [object ArgvElement]

Returns:
Type:
ArgvArray

fill(value, start, end) → {Array}

Same as Array.prototype.fill, but converts argument 1 to [object ArgvElement]

Source:
Parameters:
Name Type Description
value

converted to [object ArgvElement]

start
end
Returns:
Type:
Array

fill(value, start, end) → {Array}

Same as Array.prototype.fill, but converts argument 1 to [object ArgvElement]

Source:
Parameters:
Name Type Description
value

converted to [object ArgvElement]

start
end
Returns:
Type:
Array

get(element, params) → {ArgvElement|boolean}

search argv element

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement). Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }
params object | ArgvElement

If 1 argument is string, this is set of element parameters (template for ArgvElement)

Returns:
Type:
ArgvElement | boolean

If false, then the item was not found. If found, it returns [object ArgvElement]

Example
let argv=new ArgvArray('command1 command2 --option1=value');
 argv.get('command2'); // result =>[object ArgvElement]
 argv.get('command2',{order:2});//result => [object ArgvElement]
 argv.get('command2',{order:1});//result => false
 argv.get('--option'); // result=>[object ArgvElement]
 argv.get('--option=value');// result=>[object ArgvElement]
 argv.get('--option=val');// result=>false

get(element, params) → {ArgvElement|boolean}

search argv element

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for ArgvElement). Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }
params object | ArgvElement

If 1 argument is string, this is set of element parameters (template for ArgvElement)

Returns:
Type:
ArgvElement | boolean

If false, then the item was not found. If found, it returns [object ArgvElement]

Example
let argv=new ArgvArray('command1 command2 --option1=value');
 argv.get('command2'); // result =>[object ArgvElement]
 argv.get('command2',{order:2});//result => [object ArgvElement]
 argv.get('command2',{order:1});//result => false
 argv.get('--option'); // result=>[object ArgvElement]
 argv.get('--option=value');// result=>[object ArgvElement]
 argv.get('--option=val');// result=>false

push(…args) → {number}

Same as Array.prototype.push, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

push(…args) → {number}

Same as Array.prototype.push, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

searchElement(element, isFirst) → {Array.<ArgvElement>}

search ArgvElement in ArgvArray by keys and/or value

Source:
Parameters:
Name Type Default Description
element ArgvElement | object | string

Sets the dataset to search

{
    type, // 
    key, // Data type =>  * | string | [object RegExp]
    value, // for {type:'option'}. data type =>  * | string | [object RegExp]
    order // for {type:'command'} 
}

or pattern string for element Example:"/command1|command2/", "[--option=value]"

isFirst boolean false

one result in array

Returns:
Type:
Array.<ArgvElement>

searchElement(element, isFirst) → {Array.<ArgvElement>}

search ArgvElement in ArgvArray by keys and/or value

Source:
Parameters:
Name Type Default Description
element ArgvElement | object | string

Sets the dataset to search

{
    type, // 
    key, // Data type =>  * | string | [object RegExp]
    value, // for {type:'option'}. data type =>  * | string | [object RegExp]
    order // for {type:'command'} 
}

or pattern string for element Example:"/command1|command2/", "[--option=value]"

isFirst boolean false

one result in array

Returns:
Type:
Array.<ArgvElement>

searchElements(elements, isFirst, isCommand) → {Array|ArgvArray}

search ArgvElements

Source:
Parameters:
Name Type Default Description
elements string | Array.<string> | ArgvArray | Array.<ArgvElement> | Array.<object>

string or strings array - commandline or parametrs set command line objects array - ArgvElement templates set

[
 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 },
 ...     *
]
isFirst boolean false

isFirst - one result in array

isCommand boolean false

if isCommand===true then returns [array ArgvArray]

Returns:
Type:
Array | ArgvArray

Array - if isFirst equal true, then return argvElement array.
If isFirst equal false, then return [[ArgvElement....],[...],[...]]. If isCommand===true then returns [array ArgvArray]

searchElements(elements, isFirst, isCommand) → {Array|ArgvArray}

search ArgvElements

Source:
Parameters:
Name Type Default Description
elements string | Array.<string> | ArgvArray | Array.<ArgvElement> | Array.<object>

string or strings array - commandline or parametrs set command line objects array - ArgvElement templates set

[
 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 },
 ...     *
]
isFirst boolean false

isFirst - one result in array

isCommand boolean false

if isCommand===true then returns [array ArgvArray]

Returns:
Type:
Array | ArgvArray

Array - if isFirst equal true, then return argvElement array.
If isFirst equal false, then return [[ArgvElement....],[...],[...]]. If isCommand===true then returns [array ArgvArray]

set(element, params) → {this}

Sets a new parameter or overwrites the properties of the specified parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for [object ArgvElement]) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the element

params object | ArgvElement

if 1 argument is string, it is used as parameter setting for the element (template for [object ArgvElement])

Returns:
Type:
this

set(element, params) → {this}

Sets a new parameter or overwrites the properties of the specified parameter

Source:
Parameters:
Name Type Description
element string | object | ArgvElement

where string is the command line element for the parser. If an object, then this is a set of element parameters (template for [object ArgvElement]) Properties for element search

 {
      type, // 
      key, // Data type =>  * | string | [object RegExp]
      value, // for {type:'option'}. data type =>  * | string | [object RegExp]
     order // for {type:'command'} 
 }

Other used properties will be set to the element

params object | ArgvElement

if 1 argument is string, it is used as parameter setting for the element (template for [object ArgvElement])

Returns:
Type:
this

sort(call)

sorting items by order

Source:
Parameters:
Name Type Description
call

sort(call)

sorting items by order

Source:
Parameters:
Name Type Description
call

splice(start, deleteCount, …items) → {Array.<any>}

ame as Array.prototype.fill, but converts rest arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
start
deleteCount
items <repeatable>

converted to [object ArgvElement]

Returns:
Type:
Array.<any>

splice(start, deleteCount, …items) → {Array.<any>}

ame as Array.prototype.fill, but converts rest arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
start
deleteCount
items <repeatable>

converted to [object ArgvElement]

Returns:
Type:
Array.<any>

toArray() → {Array.<string>}

converts ArgvArray to Array

Source:
Returns:
Type:
Array.<string>

toArray() → {Array.<string>}

converts ArgvArray to Array

Source:
Returns:
Type:
Array.<string>

toElement(element) → {ArgvElement}

convert string or Array to [object ArgvElement]

Source:
Parameters:
Name Type Description
element string
Returns:
Type:
ArgvElement
Example
let argv=new ArgvArray();
let result= argv.toElement('command --option -o=value'); //[object ArgvElement]

toElement(element) → {ArgvElement}

convert string or Array to [object ArgvElement]

Source:
Parameters:
Name Type Description
element string
Returns:
Type:
ArgvElement
Example
let argv=new ArgvArray();
let result= argv.toElement('command --option -o=value'); //[object ArgvElement]

toString() → {string}

Converts ArgvArray to command line

Source:
Returns:
Type:
string

Command line

Example
let argv=new ArgvArray(['command', '--option', '-o value']);
argv.toString();
//result
//'command --option -o=value'

toString() → {string}

Converts ArgvArray to command line

Source:
Returns:
Type:
string

Command line

Example
let argv=new ArgvArray(['command', '--option', '-o value']);
argv.toString();
//result
//'command --option -o=value'

unshift(…args) → {number}

Same as Array.prototype.unshift, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number

unshift(…args) → {number}

Same as Array.prototype.unshift, but converts arguments to [object ArgvElement]

Source:
Parameters:
Name Type Attributes Description
args <repeatable>

converted to ArgvElement

Returns:
Type:
number