mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-08 10:11:21 +00:00
* feat: add `parse` function Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * chore: remoev unused shell-quote from dependencies Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * test: update `context.test.ts` test Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
19 lines
609 B
TypeScript
19 lines
609 B
TypeScript
const regex = /"([^"]*)"|'([^']*)'|`([^`]*)`|(\S+)/g;
|
|
|
|
/**
|
|
* Converts a space-separated string into a list of arguments.
|
|
*
|
|
* This function parses the provided string, which contains arguments separated by spaces and possibly enclosed in quotes, into a list of arguments.
|
|
*
|
|
* @param str - The space-separated string to parse.
|
|
* @returns A list of arguments.
|
|
*/
|
|
export function parse(str: string): string[] {
|
|
const args: string[] = [];
|
|
let match: RegExpExecArray | null;
|
|
while ((match = regex.exec(str)) !== null) {
|
|
args.push(match[1] ?? match[2] ?? match[3] ?? match[4]);
|
|
}
|
|
return args;
|
|
}
|