mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-29 02:49:13 -04:00
chore(lint): switched to a better lint config
This commit is contained in:
parent
4d2b037dbe
commit
33c9b6643f
178 changed files with 4105 additions and 3371 deletions
|
@ -1,4 +1,4 @@
|
|||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - List converter', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
|
@ -30,10 +30,10 @@ test.describe('Tool - List converter', () => {
|
|||
3
|
||||
5`);
|
||||
await page.getByTestId('removeDuplicates').check();
|
||||
await page.getByTestId('itemPrefix').fill("'");
|
||||
await page.getByTestId('itemSuffix').fill("'");
|
||||
await page.getByTestId('itemPrefix').fill('\'');
|
||||
await page.getByTestId('itemSuffix').fill('\'');
|
||||
|
||||
const result = await page.getByTestId('area-content').innerText();
|
||||
expect(result.trim()).toEqual("'1', '2', '4', '3', '5'");
|
||||
expect(result.trim()).toEqual('\'1\', \'2\', \'4\', \'3\', \'5\'');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { expect, describe, it } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { convert } from './list-converter.models';
|
||||
import type { ConvertOptions } from './list-converter.types';
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
import _ from 'lodash';
|
||||
import { byOrder } from '@/utils/array';
|
||||
import type { ConvertOptions } from './list-converter.types';
|
||||
import { byOrder } from '@/utils/array';
|
||||
|
||||
export { convert };
|
||||
|
||||
const whenever =
|
||||
<T, R>(condition: boolean, fn: (value: T) => R) =>
|
||||
(value: T) =>
|
||||
function whenever<T, R>(condition: boolean, fn: (value: T) => R) {
|
||||
return (value: T) =>
|
||||
condition ? fn(value) : value;
|
||||
}
|
||||
|
||||
function convert(list: string, options: ConvertOptions): string {
|
||||
const lineBreak = options.keepLineBreaks ? '\n' : '';
|
||||
|
||||
return _.chain(list)
|
||||
.thru(whenever(options.lowerCase, (text) => text.toLowerCase()))
|
||||
.thru(whenever(options.lowerCase, text => text.toLowerCase()))
|
||||
.split('\n')
|
||||
.thru(whenever(options.removeDuplicates, _.uniq))
|
||||
.thru(whenever(options.reverseList, _.reverse))
|
||||
.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))
|
||||
.without('')
|
||||
.map((p) => options.itemPrefix + p + options.itemSuffix)
|
||||
.map(p => options.itemPrefix + p + options.itemSuffix)
|
||||
.join(options.separator + lineBreak)
|
||||
.thru((text) => [options.listPrefix, text, options.listSuffix].join(lineBreak))
|
||||
.thru(text => [options.listPrefix, text, options.listSuffix].join(lineBreak))
|
||||
.value();
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
export type SortOrder = 'asc' | 'desc' | null;
|
||||
|
||||
export type ConvertOptions = {
|
||||
lowerCase: boolean;
|
||||
trimItems: boolean;
|
||||
itemPrefix: string;
|
||||
itemSuffix: string;
|
||||
listPrefix: string;
|
||||
listSuffix: string;
|
||||
reverseList: boolean;
|
||||
sortList: SortOrder;
|
||||
removeDuplicates: boolean;
|
||||
separator: string;
|
||||
keepLineBreaks: boolean;
|
||||
};
|
||||
export interface ConvertOptions {
|
||||
lowerCase: boolean
|
||||
trimItems: boolean
|
||||
itemPrefix: string
|
||||
itemSuffix: string
|
||||
listPrefix: string
|
||||
listSuffix: string
|
||||
reverseList: boolean
|
||||
sortList: SortOrder
|
||||
removeDuplicates: boolean
|
||||
separator: string
|
||||
keepLineBreaks: boolean
|
||||
}
|
||||
|
|
|
@ -1,3 +1,40 @@
|
|||
<script setup lang="ts">
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { convert } from './list-converter.models';
|
||||
import type { ConvertOptions } from './list-converter.types';
|
||||
|
||||
const sortOrderOptions = [
|
||||
{
|
||||
label: 'Sort ascending',
|
||||
value: 'asc',
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
label: 'Sort descending',
|
||||
value: 'desc',
|
||||
disabled: false,
|
||||
},
|
||||
];
|
||||
|
||||
const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionConfig', {
|
||||
lowerCase: false,
|
||||
trimItems: true,
|
||||
removeDuplicates: true,
|
||||
keepLineBreaks: false,
|
||||
itemPrefix: '',
|
||||
itemSuffix: '',
|
||||
listPrefix: '',
|
||||
listSuffix: '',
|
||||
reverseList: false,
|
||||
sortList: null,
|
||||
separator: ', ',
|
||||
});
|
||||
|
||||
function transformer(value: string) {
|
||||
return convert(value, conversionConfig.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="flex: 0 0 100%">
|
||||
<div style="margin: 0 auto; max-width: 600px">
|
||||
|
@ -82,42 +119,3 @@
|
|||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { convert } from './list-converter.models';
|
||||
import type { ConvertOptions } from './list-converter.types';
|
||||
|
||||
const sortOrderOptions = [
|
||||
{
|
||||
label: 'Sort ascending',
|
||||
value: 'asc',
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
label: 'Sort descending',
|
||||
value: 'desc',
|
||||
disabled: false,
|
||||
},
|
||||
];
|
||||
|
||||
const conversionConfig = useStorage<ConvertOptions>('list-converter:conversionConfig', {
|
||||
lowerCase: false,
|
||||
trimItems: true,
|
||||
removeDuplicates: true,
|
||||
keepLineBreaks: false,
|
||||
itemPrefix: '',
|
||||
itemSuffix: '',
|
||||
listPrefix: '',
|
||||
listSuffix: '',
|
||||
reverseList: false,
|
||||
sortList: null,
|
||||
separator: ', ',
|
||||
});
|
||||
|
||||
const transformer = (value: string) => {
|
||||
return convert(value, conversionConfig.value);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue