mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-16 12:58:35 +05:30
31 lines
691 B
TypeScript
31 lines
691 B
TypeScript
import { InitialValuesType } from './types';
|
|
import { splitCsv } from '@utils/csv';
|
|
|
|
export function changeCsvSeparator(
|
|
input: string,
|
|
options: InitialValuesType
|
|
): string {
|
|
if (!input) return '';
|
|
|
|
const rows = splitCsv(
|
|
input,
|
|
true,
|
|
options.commentCharacter,
|
|
options.emptyLines,
|
|
options.inputSeparator,
|
|
options.inputQuoteCharacter
|
|
);
|
|
|
|
return rows
|
|
.map((row) => {
|
|
return row
|
|
.map((cell) => {
|
|
if (options.outputQuoteAll) {
|
|
return `${options.OutputQuoteCharacter}${cell}${options.OutputQuoteCharacter}`;
|
|
}
|
|
return cell;
|
|
})
|
|
.join(options.outputSeparator);
|
|
})
|
|
.join('\n');
|
|
}
|