I have following codes in a file. Please note that VS code inserts a new line after export let theadClass =
when I save the file.
<script lang="ts">
export let header: Array<string>;
export let divClass: string = 'relative overflow-x-auto shadow-md sm:rounded-lg';
export let tableClass: string = 'w-full text-sm text-left text-gray-500 dark:text-gray-400';
export let theadClass: string =
'text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400';
</script>
<div class={divClass}>
// more after this line ...
</div>
Ideally I'd like to extract as following to create a prop table. But it is ok if I extract strings between export
to ;
as well.
header: Array<string>;
divClass:string = 'relative overflow-x-auto shadow-md sm:rounded-lg';
tableClass:string = 'w-full text-sm text-left text-gray-500 dark:text-gray-400';
theadClass:string = 'text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400';
When I use the following funciton:
import * as fs from 'fs';
export function getLines(fileName, keyword) {
let outputs =[];
const file = fs.readFileSync(fileName, {encoding: 'utf-8'});
let arr = file.split(/\r?\n/);
arr.forEach((line, idx) => {
if(line.includes(keyword)){
outputs.push(line);
}
});
return outputs
}
I get the following:
[
'\texport let header: Array<string>;',
"\texport let divClass: string = 'relative overflow-x-auto shadow-md sm:rounded-lg';",
"\texport let tableClass: string = 'w-full text-sm text-left text-gray-500 dark:text-gray-400';",
'\texport let theadClass: string ='
]
As you can see it, the last line is not complete.
How can I extract lines that have export
to ;
?