mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 06:55:06 -04:00

* feat(list-converter): a small converter who deals with column based data and do some stuff with it * Update src/tools/list-converter/index.ts * Update src/tools/list-converter/index.ts * Update src/tools/list-converter/index.ts --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com> fix(list-format): fix e2e
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { expect, describe, it } from 'vitest';
|
|
import { convert } from './list-converter.models';
|
|
import type { ConvertOptions } from './list-converter.types';
|
|
|
|
describe('list-converter', () => {
|
|
describe('convert', () => {
|
|
it('should convert a given list', () => {
|
|
const options: ConvertOptions = {
|
|
separator: ', ',
|
|
trimItems: true,
|
|
removeDuplicates: true,
|
|
itemPrefix: '"',
|
|
itemSuffix: '"',
|
|
listPrefix: '',
|
|
listSuffix: '',
|
|
reverseList: false,
|
|
sortList: null,
|
|
lowerCase: false,
|
|
keepLineBreaks: false,
|
|
};
|
|
const input = `
|
|
1
|
|
2
|
|
|
|
3
|
|
3
|
|
4
|
|
`;
|
|
expect(convert(input, options)).toEqual('"1", "2", "3", "4"');
|
|
});
|
|
|
|
it('should return an empty value for an empty input', () => {
|
|
const options: ConvertOptions = {
|
|
separator: ', ',
|
|
trimItems: true,
|
|
removeDuplicates: true,
|
|
itemPrefix: '',
|
|
itemSuffix: '',
|
|
listPrefix: '',
|
|
listSuffix: '',
|
|
reverseList: false,
|
|
sortList: null,
|
|
lowerCase: false,
|
|
keepLineBreaks: false,
|
|
};
|
|
expect(convert('', options)).toEqual('');
|
|
});
|
|
|
|
it('should keep line breaks', () => {
|
|
const options: ConvertOptions = {
|
|
separator: '',
|
|
trimItems: true,
|
|
itemPrefix: '<li>',
|
|
itemSuffix: '</li>',
|
|
listPrefix: '<ul>',
|
|
listSuffix: '</ul>',
|
|
keepLineBreaks: true,
|
|
lowerCase: false,
|
|
removeDuplicates: false,
|
|
reverseList: false,
|
|
sortList: null,
|
|
};
|
|
const input = `
|
|
1
|
|
2
|
|
3
|
|
`;
|
|
const expected = `<ul>
|
|
<li>1</li>
|
|
<li>2</li>
|
|
<li>3</li>
|
|
</ul>`;
|
|
expect(convert(input, options)).toEqual(expected);
|
|
});
|
|
});
|
|
});
|