mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 15:26:15 -04:00
parent
318fb6efb9
commit
327ff11a59
4 changed files with 54 additions and 0 deletions
|
@ -11,6 +11,8 @@ describe('list-converter', () => {
|
||||||
removeDuplicates: true,
|
removeDuplicates: true,
|
||||||
itemPrefix: '"',
|
itemPrefix: '"',
|
||||||
itemSuffix: '"',
|
itemSuffix: '"',
|
||||||
|
removeItemPrefix: '',
|
||||||
|
removeItemSuffix: '',
|
||||||
listPrefix: '',
|
listPrefix: '',
|
||||||
listSuffix: '',
|
listSuffix: '',
|
||||||
reverseList: false,
|
reverseList: false,
|
||||||
|
@ -36,6 +38,8 @@ describe('list-converter', () => {
|
||||||
removeDuplicates: true,
|
removeDuplicates: true,
|
||||||
itemPrefix: '',
|
itemPrefix: '',
|
||||||
itemSuffix: '',
|
itemSuffix: '',
|
||||||
|
removeItemPrefix: '',
|
||||||
|
removeItemSuffix: '',
|
||||||
listPrefix: '',
|
listPrefix: '',
|
||||||
listSuffix: '',
|
listSuffix: '',
|
||||||
reverseList: false,
|
reverseList: false,
|
||||||
|
@ -52,6 +56,8 @@ describe('list-converter', () => {
|
||||||
trimItems: true,
|
trimItems: true,
|
||||||
itemPrefix: '<li>',
|
itemPrefix: '<li>',
|
||||||
itemSuffix: '</li>',
|
itemSuffix: '</li>',
|
||||||
|
removeItemPrefix: '',
|
||||||
|
removeItemSuffix: '',
|
||||||
listPrefix: '<ul>',
|
listPrefix: '<ul>',
|
||||||
listSuffix: '</ul>',
|
listSuffix: '</ul>',
|
||||||
keepLineBreaks: true,
|
keepLineBreaks: true,
|
||||||
|
@ -72,5 +78,34 @@ describe('list-converter', () => {
|
||||||
</ul>`;
|
</ul>`;
|
||||||
expect(convert(input, options)).toEqual(expected);
|
expect(convert(input, options)).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove prefix and suffix', () => {
|
||||||
|
const options: ConvertOptions = {
|
||||||
|
separator: '',
|
||||||
|
trimItems: true,
|
||||||
|
itemPrefix: '',
|
||||||
|
itemSuffix: '',
|
||||||
|
removeItemPrefix: '\<li\>',
|
||||||
|
removeItemSuffix: '\</li\>',
|
||||||
|
listPrefix: '',
|
||||||
|
listSuffix: '',
|
||||||
|
keepLineBreaks: true,
|
||||||
|
lowerCase: false,
|
||||||
|
removeDuplicates: false,
|
||||||
|
reverseList: false,
|
||||||
|
sortList: null,
|
||||||
|
};
|
||||||
|
const input = `
|
||||||
|
<li>1</li>
|
||||||
|
<li>2</li>
|
||||||
|
<li>3</li>
|
||||||
|
`;
|
||||||
|
const expected = `
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
`;
|
||||||
|
expect(convert(input, options)).toEqual(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,8 @@ function convert(list: string, options: ConvertOptions): string {
|
||||||
.thru(whenever(!_.isNull(options.sortList), parts => parts.sort(byOrder({ order: options.sortList }))))
|
.thru(whenever(!_.isNull(options.sortList), parts => parts.sort(byOrder({ order: options.sortList }))))
|
||||||
.map(whenever(options.trimItems, _.trim))
|
.map(whenever(options.trimItems, _.trim))
|
||||||
.without('')
|
.without('')
|
||||||
|
.map(p => options.removeItemPrefix ? p.replace(new RegExp(`^${options.removeItemPrefix}`, 'g'), '') : p)
|
||||||
|
.map(p => options.removeItemSuffix ? p.replace(new RegExp(`${options.removeItemSuffix}$`, 'g'), '') : p)
|
||||||
.map(p => options.itemPrefix + p + options.itemSuffix)
|
.map(p => options.itemPrefix + p + options.itemSuffix)
|
||||||
.join(options.separator + lineBreak)
|
.join(options.separator + lineBreak)
|
||||||
.thru(text => [options.listPrefix, text, options.listSuffix].join(lineBreak))
|
.thru(text => [options.listPrefix, text, options.listSuffix].join(lineBreak))
|
||||||
|
|
|
@ -5,6 +5,8 @@ export interface ConvertOptions {
|
||||||
trimItems: boolean
|
trimItems: boolean
|
||||||
itemPrefix: string
|
itemPrefix: string
|
||||||
itemSuffix: string
|
itemSuffix: string
|
||||||
|
removeItemPrefix: string
|
||||||
|
removeItemSuffix: string
|
||||||
listPrefix: string
|
listPrefix: string
|
||||||
listSuffix: string
|
listSuffix: string
|
||||||
reverseList: boolean
|
reverseList: boolean
|
||||||
|
|
|
@ -23,6 +23,8 @@ const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionCo
|
||||||
keepLineBreaks: false,
|
keepLineBreaks: false,
|
||||||
itemPrefix: '',
|
itemPrefix: '',
|
||||||
itemSuffix: '',
|
itemSuffix: '',
|
||||||
|
removeItemPrefix: '',
|
||||||
|
removeItemSuffix: '',
|
||||||
listPrefix: '',
|
listPrefix: '',
|
||||||
listSuffix: '',
|
listSuffix: '',
|
||||||
reverseList: false,
|
reverseList: false,
|
||||||
|
@ -85,6 +87,19 @@ function transformer(value: string) {
|
||||||
placeholder=","
|
placeholder=","
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<n-form-item label="Unwrap item" label-placement="left" label-width="120" :show-feedback="false" mb-2>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="conversionConfig.removeItemPrefix"
|
||||||
|
placeholder="Remove item prefix regex"
|
||||||
|
test-id="removeItemPrefix"
|
||||||
|
/>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="conversionConfig.removeItemSuffix"
|
||||||
|
placeholder="Remove item suffix regex"
|
||||||
|
test-id="removeItemSuffix"
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
|
||||||
<n-form-item label="Wrap item" label-placement="left" label-width="120" :show-feedback="false" mb-2>
|
<n-form-item label="Wrap item" label-placement="left" label-width="120" :show-feedback="false" mb-2>
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="conversionConfig.itemPrefix"
|
v-model:value="conversionConfig.itemPrefix"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue