Skip to content

Commit 327ff11

Browse files
committed
feat(List Converter): add remove prefix/suffix capability
Fix CorentinTh#702
1 parent 318fb6e commit 327ff11

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/tools/list-converter/list-converter.models.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ describe('list-converter', () => {
1111
removeDuplicates: true,
1212
itemPrefix: '"',
1313
itemSuffix: '"',
14+
removeItemPrefix: '',
15+
removeItemSuffix: '',
1416
listPrefix: '',
1517
listSuffix: '',
1618
reverseList: false,
@@ -36,6 +38,8 @@ describe('list-converter', () => {
3638
removeDuplicates: true,
3739
itemPrefix: '',
3840
itemSuffix: '',
41+
removeItemPrefix: '',
42+
removeItemSuffix: '',
3943
listPrefix: '',
4044
listSuffix: '',
4145
reverseList: false,
@@ -52,6 +56,8 @@ describe('list-converter', () => {
5256
trimItems: true,
5357
itemPrefix: '<li>',
5458
itemSuffix: '</li>',
59+
removeItemPrefix: '',
60+
removeItemSuffix: '',
5561
listPrefix: '<ul>',
5662
listSuffix: '</ul>',
5763
keepLineBreaks: true,
@@ -72,5 +78,34 @@ describe('list-converter', () => {
7278
</ul>`;
7379
expect(convert(input, options)).toEqual(expected);
7480
});
81+
82+
it('should remove prefix and suffix', () => {
83+
const options: ConvertOptions = {
84+
separator: '',
85+
trimItems: true,
86+
itemPrefix: '',
87+
itemSuffix: '',
88+
removeItemPrefix: '\<li\>',
89+
removeItemSuffix: '\</li\>',
90+
listPrefix: '',
91+
listSuffix: '',
92+
keepLineBreaks: true,
93+
lowerCase: false,
94+
removeDuplicates: false,
95+
reverseList: false,
96+
sortList: null,
97+
};
98+
const input = `
99+
<li>1</li>
100+
<li>2</li>
101+
<li>3</li>
102+
`;
103+
const expected = `
104+
1
105+
2
106+
3
107+
`;
108+
expect(convert(input, options)).toEqual(expected);
109+
});
75110
});
76111
});

src/tools/list-converter/list-converter.models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function convert(list: string, options: ConvertOptions): string {
2020
.thru(whenever(!_.isNull(options.sortList), parts => parts.sort(byOrder({ order: options.sortList }))))
2121
.map(whenever(options.trimItems, _.trim))
2222
.without('')
23+
.map(p => options.removeItemPrefix ? p.replace(new RegExp(`^${options.removeItemPrefix}`, 'g'), '') : p)
24+
.map(p => options.removeItemSuffix ? p.replace(new RegExp(`${options.removeItemSuffix}$`, 'g'), '') : p)
2325
.map(p => options.itemPrefix + p + options.itemSuffix)
2426
.join(options.separator + lineBreak)
2527
.thru(text => [options.listPrefix, text, options.listSuffix].join(lineBreak))

src/tools/list-converter/list-converter.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface ConvertOptions {
55
trimItems: boolean
66
itemPrefix: string
77
itemSuffix: string
8+
removeItemPrefix: string
9+
removeItemSuffix: string
810
listPrefix: string
911
listSuffix: string
1012
reverseList: boolean

src/tools/list-converter/list-converter.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionCo
2323
keepLineBreaks: false,
2424
itemPrefix: '',
2525
itemSuffix: '',
26+
removeItemPrefix: '',
27+
removeItemSuffix: '',
2628
listPrefix: '',
2729
listSuffix: '',
2830
reverseList: false,
@@ -85,6 +87,19 @@ function transformer(value: string) {
8587
placeholder=","
8688
/>
8789

90+
<n-form-item label="Unwrap item" label-placement="left" label-width="120" :show-feedback="false" mb-2>
91+
<c-input-text
92+
v-model:value="conversionConfig.removeItemPrefix"
93+
placeholder="Remove item prefix regex"
94+
test-id="removeItemPrefix"
95+
/>
96+
<c-input-text
97+
v-model:value="conversionConfig.removeItemSuffix"
98+
placeholder="Remove item suffix regex"
99+
test-id="removeItemSuffix"
100+
/>
101+
</n-form-item>
102+
88103
<n-form-item label="Wrap item" label-placement="left" label-width="120" :show-feedback="false" mb-2>
89104
<c-input-text
90105
v-model:value="conversionConfig.itemPrefix"

0 commit comments

Comments
 (0)