refactor: default csv-parse params
This commit is contained in:
@@ -6,6 +6,9 @@ export interface CsvLoaderOptions {
|
||||
delimiter?: string;
|
||||
quote?: string;
|
||||
escape?: string;
|
||||
bom?: boolean;
|
||||
comment?: string | false;
|
||||
trim?: boolean;
|
||||
}
|
||||
|
||||
interface PropertyConfig {
|
||||
@@ -19,15 +22,21 @@ export default function csvLoader(
|
||||
this: LoaderContext<CsvLoaderOptions>,
|
||||
content: string
|
||||
): string | Buffer {
|
||||
const options = this.getOptions() || {};
|
||||
const delimiter = options.delimiter ?? ',';
|
||||
const quote = options.quote ?? '"';
|
||||
const escape = options.escape ?? '\\';
|
||||
const options = this.getOptions() as CsvLoaderOptions | undefined;
|
||||
const delimiter = options?.delimiter ?? ',';
|
||||
const quote = options?.quote ?? '"';
|
||||
const escape = options?.escape ?? '\\';
|
||||
const bom = options?.bom ?? true;
|
||||
const comment = options?.comment === false ? undefined : (options?.comment ?? '#');
|
||||
const trim = options?.trim ?? true;
|
||||
|
||||
const records = parse(content, {
|
||||
delimiter,
|
||||
quote,
|
||||
escape,
|
||||
bom,
|
||||
comment,
|
||||
trim,
|
||||
relax_column_count: true,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user