Constructor
new Scope(name)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the scope. |
Throws:
-
If the
name
is not astring
. - Type
- TypeError
Members
name :string
The scope's name.
Type:
Methods
addCase(theCase) → {Scope}
Adds a new case to the scope.
Parameters:
Name | Type | Description |
---|---|---|
theCase |
ErrorCase | The case to add. |
Throws:
-
-
If there's already a case with the same name on the scope.
- Type
- Error
-
Returns:
For chaining purposes.
- Type
- Scope
addParser(parser) → {Scope}
Adds a reusable parser to the scope.
Parameters:
Name | Type | Description |
---|---|---|
parser |
CaseParser | The parser to add. |
Throws:
-
-
If there's already a parser with the same name on the scope.
- Type
- Error
-
-
-
If
parser
is not an instance ofCaseParser
. - Type
- Error
-
Returns:
For chaining purposes.
- Type
- Scope
getCase(name, failWithErroropt) → (nullable) {ErrorCase}
Returns a case by its name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The name of the case. |
||
failWithError |
boolean |
<optional> |
true
|
Whether or not the method should throw an error if the case can't be found. |
Throws:
-
If
failWithError
istrue
and the case can't be found. - Type
- Error
Returns:
- Type
- ErrorCase
getCases() → {Array.<ErrorCase>}
Returns all available cases for this scope.
Returns:
getParser(name, failWithErroropt) → (nullable) {CaseParser}
Returns a parser by its name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | The name of the parser. |
||
failWithError |
boolean |
<optional> |
true
|
Whether or not the method should throw an error if the parser can't be found. |
Throws:
-
If
failWithError
istrue
and the parser can't be found. - Type
- Error
Returns:
- Type
- CaseParser
hasCase(name) → {boolean}
Checks whether or not there's a case based on its name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The case's name. |
Returns:
- Type
- boolean
hasParser(name) → {boolean}
Checks whether or not there's a parser based on its name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The parser's name. |
Returns:
- Type
- boolean
removeCase(theCase) → {Scope}
Removes a case from the scope.
Parameters:
Name | Type | Description |
---|---|---|
theCase |
string | ErrorCase | The name or the reference for the case to remove. |
Throws:
-
-
If the case doesn't exist on the scope.
- Type
- Error
-
Returns:
For chaining purposes.
- Type
- Scope
removeParser(parser) → {Scope}
Removes a parser from the scope.
Parameters:
Name | Type | Description |
---|---|---|
parser |
string | CaseParser | The name or the reference for the parser to remove. |
Throws:
-
-
If the parser doesn't exist on the scope.
- Type
- Error
-
-
-
If
parser
is a reference but is not an instance ofCaseParser
. - Type
- Error
-
Returns:
For chaining purposes.
- Type
- Scope