chore(lint): switched to a better lint config

This commit is contained in:
Corentin Thomasset 2023-05-28 23:13:24 +02:00 committed by Corentin THOMASSET
parent 4d2b037dbe
commit 33c9b6643f
178 changed files with 4105 additions and 3371 deletions

View file

@ -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();
}