mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(List Converter): filter item regexps
This commit is contained in:
1 parent
b853dfa0d4
commit
330b18d945
5 files changed
+41
No files matched your search
@@ -530,6 +530,9 @@ tools:
|
||||
placeholder-t-tools-list-converter-texts-input-placeholder-paste-your-input-data-here: >-
|
||||
t('tools.list-converter.texts.input-placeholder-paste-your-input-data-here')
|
||||
label-t-tools-list-converter-texts-output-label-your-transformed-data: t('tools.list-converter.texts.output-label-your-transformed-data')
|
||||
label-filter-item: Filter items by Regex
|
||||
placeholder-remove-item-filter-regex: Filter Regex
|
||||
placeholder-remove-item-not-filter-regex: Not Filter Regex
|
||||
base64-string-converter:
|
||||
title: Base64 string encoder/decoder
|
||||
description: Simply encode and decode strings into their base64 representation.
|
||||
|
||||
@@ -113,5 +113,22 @@ describe('list-converter', () => {
|
||||
1`;
|
||||
expect(convert(input, options)).toEqual(expected);
|
||||
});
|
||||
it('should filter', () => {
|
||||
const options: ConvertOptions = {
|
||||
keepLineBreaks: true,
|
||||
sortList: undefined,
|
||||
filterRegex: String.raw`^\d`,
|
||||
notFilterRegex: '^10',
|
||||
};
|
||||
const input = `1
|
||||
20
|
||||
10
|
||||
a
|
||||
3`;
|
||||
const expected = `1
|
||||
20
|
||||
3`;
|
||||
expect(convert(input, options)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -14,12 +14,16 @@ function convert(list: string, options: ConvertOptions): string {
|
||||
|
||||
const splitSep = options.splitBySeparator ? `${options.splitBySeparator}|` : '';
|
||||
const splitRegExp = new RegExp(`(?:${splitSep}\\n)`, 'g');
|
||||
const filterRegExp = options.filterRegex ? new RegExp(options.filterRegex, 'v') : null;
|
||||
const notFilterRegExp = options.notFilterRegex ? new RegExp(options.notFilterRegex, 'v') : null;
|
||||
return _.chain(list)
|
||||
.thru(whenever(options.lowerCase, text => text.toLowerCase()))
|
||||
.split(splitRegExp)
|
||||
.thru(whenever(options.removeDuplicates, _.uniq))
|
||||
.thru(whenever(options.reverseList, _.reverse))
|
||||
.map(whenever(options.trimItems, _.trim))
|
||||
.filter(text => filterRegExp === null || filterRegExp?.test(text))
|
||||
.filter(text => notFilterRegExp === null || !notFilterRegExp?.test(text))
|
||||
.thru(whenever(!!options.sortList, parts => parts.sort(byOrder({ order: options.sortList }))))
|
||||
.without('')
|
||||
.map(p => options.removeItemPrefix ? p.replace(new RegExp(`^${options.removeItemPrefix}`, 'g'), '') : p)
|
||||
|
||||
@@ -15,4 +15,6 @@ export interface ConvertOptions {
|
||||
itemsSeparator?: string
|
||||
splitBySeparator?: string
|
||||
keepLineBreaks?: boolean
|
||||
filterRegex?: string
|
||||
notFilterRegex?: string
|
||||
}
|
||||
@@ -61,6 +61,8 @@ const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionCo
|
||||
sortList: null,
|
||||
itemsSeparator: ', ',
|
||||
splitBySeparator: '',
|
||||
filterRegex: '',
|
||||
notFilterRegex: '',
|
||||
});
|
||||
|
||||
function transformer(value: string) {
|
||||
@@ -128,6 +130,19 @@ function transformer(value: string) {
|
||||
:placeholder="t('tools.list-converter.texts.placeholder-separator-for-splitting')"
|
||||
/>
|
||||
|
||||
<n-form-item :label="t('tools.list-converter.texts.label-filter-item')" label-placement="left" label-width="120" :show-feedback="false" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="conversionConfig.filterRegex"
|
||||
:placeholder="t('tools.list-converter.texts.placeholder-remove-item-filter-regex')"
|
||||
test-id="filterRegex"
|
||||
/>
|
||||
<c-input-text
|
||||
v-model:value="conversionConfig.notFilterRegex"
|
||||
:placeholder="t('tools.list-converter.texts.placeholder-remove-item-not-filter-regex')"
|
||||
test-id="notFilterRegex"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item :label="t('tools.list-converter.texts.label-unwrap-item')" label-placement="left" label-width="120" :show-feedback="false" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="conversionConfig.removeItemPrefix"
|
||||
|
||||
Reference in new issue
Block a user