Shells out to Powershell PSParser module and returns results in neat array
npm install psparserjavascript
const PSParser = require('psparser');
const main = async () => {
const psParser = new PSParser();
const tokens = await psparser.parse('echo hello');
psParser.dispose(); // always call dispose when you are done with PSPaser.
// work with tokens :)
};
`General output
This library directly translates the output of PSParser.Tokens will be an array containing objects of the following type:
`typescript
enum TokenType {
Attribute = 9,
Command = 1,
CommandArgument = 3,
CommandParameter = 2,
Comment = 15,
GroupEnd = 13,
GroupStart = 12,
Keyword = 14,
LineContinuation = 18,
LoopLabel = 8,
Member = 7,
NewLine = 17 ,
Number = 4,
Operator = 11,
Position = 19,
StatementSeparator = 16,
String = 5,
Type = 10,
Unknown = 0,
Variable = 6
};interface Token {
content: string;
type: TokenType;
start: number;
length: number;
startLine: number;
startColumn: number;
endLine: number;
endColumn: number;
}
`You can access
TOKEN_TYPE enum directly off of PSParser.TOKEN_TYPE`.