mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-02 12:29:13 -04:00
feat(list-converter): a small converter who deals with column based data and do some stuff with it (#387)
* 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
This commit is contained in:
parent
ce3150c65d
commit
83a7b3bae9
9 changed files with 441 additions and 139 deletions
76
src/tools/list-converter/list-converter.models.test.ts
Normal file
76
src/tools/list-converter/list-converter.models.test.ts
Normal file
|
@ -0,0 +1,76 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue