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,
|
||||
itemPrefix: '"',
|
||||
itemSuffix: '"',
|
||||
removeItemPrefix: '',
|
||||
removeItemSuffix: '',
|
||||
listPrefix: '',
|
||||
listSuffix: '',
|
||||
reverseList: false,
|
||||
|
@ -36,6 +38,8 @@ describe('list-converter', () => {
|
|||
removeDuplicates: true,
|
||||
itemPrefix: '',
|
||||
itemSuffix: '',
|
||||
removeItemPrefix: '',
|
||||
removeItemSuffix: '',
|
||||
listPrefix: '',
|
||||
listSuffix: '',
|
||||
reverseList: false,
|
||||
|
@ -52,6 +56,8 @@ describe('list-converter', () => {
|
|||
trimItems: true,
|
||||
itemPrefix: '<li>',
|
||||
itemSuffix: '</li>',
|
||||
removeItemPrefix: '',
|
||||
removeItemSuffix: '',
|
||||
listPrefix: '<ul>',
|
||||
listSuffix: '</ul>',
|
||||
keepLineBreaks: true,
|
||||
|
@ -72,5 +78,34 @@ describe('list-converter', () => {
|
|||
</ul>`;
|
||||
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 }))))
|
||||
.map(whenever(options.trimItems, _.trim))
|
||||
.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)
|
||||
.join(options.separator + lineBreak)
|
||||
.thru(text => [options.listPrefix, text, options.listSuffix].join(lineBreak))
|
||||
|
|
|
@ -5,6 +5,8 @@ export interface ConvertOptions {
|
|||
trimItems: boolean
|
||||
itemPrefix: string
|
||||
itemSuffix: string
|
||||
removeItemPrefix: string
|
||||
removeItemSuffix: string
|
||||
listPrefix: string
|
||||
listSuffix: string
|
||||
reverseList: boolean
|
||||
|
|
|
@ -23,6 +23,8 @@ const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionCo
|
|||
keepLineBreaks: false,
|
||||
itemPrefix: '',
|
||||
itemSuffix: '',
|
||||
removeItemPrefix: '',
|
||||
removeItemSuffix: '',
|
||||
listPrefix: '',
|
||||
listSuffix: '',
|
||||
reverseList: false,
|
||||
|
@ -85,6 +87,19 @@ function transformer(value: string) {
|
|||
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>
|
||||
<c-input-text
|
||||
v-model:value="conversionConfig.itemPrefix"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue