diff options
Diffstat (limited to 'examples/macros/matchInFile.tsx')
-rw-r--r-- | examples/macros/matchInFile.tsx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/macros/matchInFile.tsx b/examples/macros/matchInFile.tsx new file mode 100644 index 000000000..a73f7ee8b --- /dev/null +++ b/examples/macros/matchInFile.tsx @@ -0,0 +1,20 @@ +// macro code +export function matchInFile(callExpression) { + const [filePathNode, matcherNode] = callExpression.arguments; + const filePath: string = filePathNode.get(); + const matcher: RegExp = matcherNode.get(); + const file: string = Bun.readFile(Bun.cwd + filePath); + + return ( + <array> + {file + .split("\n") + .map((line) => line.match(matcher)) + .filter(Boolean) + .reverse() + .map((line) => ( + <string value={line[0]} /> + ))} + </array> + ); +} |