The parser output.
The parser output.
The state of this instance.
Whether all ordered tokens have been used.
The amount of ordered tokens.
The amount of remaining ordered tokens.
Filters and retrieves all unused tokens that could be transformed. Those tokens will now be consider used.
// Suppose args are from '1 2 3'.
const parse = (x: string) => {
const n = Number(x);
return isNaN(n) || n === 1 ? none() : some(n);
};
console.log(args.filterMap(parse));
>>> [2, 3]
Output type.
Gives an option of either the resulting value, or nothing if failed.
The limit on the amount of tokens to retrieve; defaults to infinite.
Where to start looking for tokens; defaults to current position.
The resulting values.
Filters and retrieves all unused tokens that could be transformed.
This variant of the function is asynchronous using Promise
.
Those tokens will now be consider used.
Output type.
Gives an option of either the resulting value, or nothing if failed.
The limit on the amount of tokens to retrieve; defaults to infinite.
Where to start looking for tokens; defaults to current position.
The resulting values.
Finds and retrieves the first unused token that could be transformed. That token will now be consider used.
// Suppose args are from '1 2 3'.
const parse = (x: string) => {
const n = Number(x);
return isNaN(n) || n === 1 ? none() : some(n);
};
console.log(args.findMap(parse));
>>> { exists: true, value: 2 }
Output type.
Gives an option of either the resulting value, or nothing if failed.
Where to start looking for tokens; defaults to current position.
The resulting value if it was found.
Finds and retrieves the first unused token that could be transformed.
This variant of the function is asynchronous using Promise
.
That token will now be consider used.
Output type.
Gives an option of either the resulting value, or nothing if failed.
Where to start looking for tokens; defaults to current position.
The resulting value if it was found.
Finds and retrieves the first unused token that could be transformed. That token will now be consider used. This is a variant of {@linkcode Args#findMap} that allows for a Result to be returned.
Output type.
Error type.
Gives a result of either the resulting value, or an error.
Where to start looking for tokens; defaults to current position.
The resulting value if it was found or a list of errors during parsing.
Finds and retrieves the first unused token that could be transformed.
That token will now be consider used.
This variant of the function is asynchronous using Promise
.
This is a variant of {@linkcode Args#findMapAsync} that allows for a Result to be returned.
Output type.
Error type.
Gives a result of either the resulting value, or an error.
Where to start looking for tokens; defaults to current position.
The resulting value if it was found or a list of errors during parsing.
Checks if a flag was given.
// Suppose args are from '--f --g'.
console.log(args.flag('f'));
>>> true
console.log(args.flag('g', 'h'));
>>> true
console.log(args.flag('h'));
>>> false
The name(s) of the flag.
Whether the flag was given.
Retrieves many unused tokens.
// Suppose args are from '1 2 3'.
const xs = args.many();
console.log(joinTokens(xs));
>>> '1 2 3'
// Suppose args are from '1 2 3'.
const xs = args.many(2);
console.log(joinTokens(xs));
>>> '1 2'
The limit on the amount of tokens to retrieve; defaults to infinite.
Where to start looking for tokens; defaults to current position.
The tokens.
Retrieves many unused tokens from the end. Note that the order of retrieved tokens will be the same order as in the ordered tokens list.
// Suppose args are from '1 2 3'.
const xs = args.manyFromEnd();
console.log(joinTokens(xs));
>>> '1 2 3'
// Suppose args are from '1 2 3'.
const xs = args.manyFromEnd(2);
console.log(joinTokens(xs));
>>> '2 3'
The limit on the amount of tokens to retrieve; defaults to infinite.
Where to start looking for tokens; defaults to current position from end.
The tokens.
Gets the next ordered argument.
An iterator result containing a string.
Gets the last value of an option.
// Suppose args are from '--a=1 --b=2 --c=3'.
console.log(args.option('a'));
>>> '1'
console.log(args.option('b', 'c'));
>>> '2'
console.log(args.option('d'));
>>> null
The name(s) of the option.
The last value of the option if it was given. When there are multiple names, the last value of the first found name is given.
Gets all the values of an option.
// Suppose args are from '--a=1 --a=1 --b=2 --c=3'.
console.log(args.options('a'));
>>> ['1', '1']
console.log(args.option('b', 'c'));
>>> ['2', '3']
console.log(args.option('d'));
>>> null
The name(s) of the option.
The values of the option if it was given.
Get the remaining arguments as a string.
Sets the current state to the given state from {@linkcode Args#save}. Use this to backtrack after a series of retrievals.
State to restore to.
Saves the current state that can then be restored later by using {@linkcode Args#restore}.
The current state.
Retrieves the value of the next unused ordered token. That token will now be consider used.
// Suppose args are from '1 2 3'.
console.log(args.single());
>>> '1'
console.log(args.single());
>>> '2'
console.log(args.single());
>>> '3'
console.log(args.single());
>>> null
The value if there are tokens left.
Retrieves the value of the next unused ordered token from the end. That token will now be consider used.
// Suppose args are from '1 2 3'.
console.log(args.singleFromEnd());
>>> '3'
console.log(args.singleFromEnd());
>>> '2'
console.log(args.singleFromEnd());
>>> '1'
console.log(args.singleFromEnd());
>>> null
The value if there are tokens left.
Retrieves the value of the next unused ordered token, but only if it could be transformed. That token will now be consider used if the transformation succeeds.
// Suppose args are from '1 2 3'.
const parse = (x: string) => {
const n = Number(x);
return isNaN(n) ? none() : some(n);
};
console.log(args.singleMap(parse));
>>> { exists: true, value: 1 }
Output type.
Gives an option of either the resulting value, or nothing if failed.
Whether to consider the token used even if the transformation fails; defaults to false.
The value if the transformation succeeds. If there are no tokens left, null is returned.
Retrieves the value of the next unused ordered token, but only if it could be transformed.
This variant of the function is asynchronous using Promise
.
That token will now be consider used if the transformation succeeds.
Output type.
Gives an option of either the resulting value, or nothing if failed.
Whether to consider the token used even if the transformation fails; defaults to false.
The value if the transformation succeeds. If there are no tokens left, null is returned.
Retrieves the value of the next unused ordered token, but only if it could be transformed. That token will now be consider used if the transformation succeeds. This is a variant of {@linkcode Args#singleMap} that allows for a Result to be returned.
// Suppose args are from '1 a'.
const parse = (x: string) => {
const n = Number(x);
return isNaN(n) ? err(x + ' is not a number') : ok(n);
};
console.log(args.singleParse(parse));
>>> { success: true, value: 1 }
console.log(args.singleParse(parse));
>>> { success: false, error: 'a is not a number' }
console.log(args.singleParse(parse));
>>> null
Output type.
Error type.
Gives a result of either the resulting value, or an error.
Whether to consider the token used even if the transformation fails; defaults to false.
The result which succeeds if the transformation succeeds. If there are no tokens left, null is returned.
Retrieves the value of the next unused ordered token, but only if it could be transformed.
That token will now be consider used if the transformation succeeds.
This variant of the function is asynchronous using Promise
.
This is a variant of {@linkcode Args#singleMapAsync} that allows for a Result to be returned.
Output type.
Error type.
Gives a result of either the resulting value, or an error.
Whether to consider the token used even if the transformation fails; defaults to false.
The result which succeeds if the transformation succeeds. If there are no tokens left, null is returned.
A class that represents a set of arguments.