mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
update top list items functions to (1) replace special characters by symbols when building the dict and (2) take a built array with custom regex as input.
This commit is contained in:
@@ -9,7 +9,20 @@ function dictMaker(
|
||||
): { [key: string]: number } {
|
||||
const dict: { [key: string]: number } = {};
|
||||
for (const item of array) {
|
||||
const key = ignoreItemCase ? item.toLowerCase() : item;
|
||||
let key = ignoreItemCase ? item.toLowerCase() : item;
|
||||
|
||||
const specialCharMap: { [key: string]: string } = {
|
||||
' ': '␣',
|
||||
'\n': '↲',
|
||||
'\t': '⇥',
|
||||
'\r': '␍',
|
||||
'\f': '␌',
|
||||
'\v': '␋'
|
||||
};
|
||||
if (key in specialCharMap) {
|
||||
key = specialCharMap[key];
|
||||
}
|
||||
|
||||
dict[key] = (dict[key] || 0) + 1;
|
||||
}
|
||||
return dict;
|
||||
@@ -74,21 +87,27 @@ export function TopItemsList(
|
||||
sortingMethod: SortingMethod,
|
||||
displayFormat: DisplayFormat,
|
||||
splitSeparator: string,
|
||||
input: string,
|
||||
input: string | string[],
|
||||
deleteEmptyItems: boolean,
|
||||
ignoreItemCase: boolean,
|
||||
trimItems: boolean
|
||||
): string {
|
||||
if (!input) return '';
|
||||
|
||||
let array: string[];
|
||||
switch (splitOperatorType) {
|
||||
case 'symbol':
|
||||
array = input.split(splitSeparator);
|
||||
break;
|
||||
case 'regex':
|
||||
array = input
|
||||
.split(new RegExp(splitSeparator))
|
||||
.filter((item) => item !== '');
|
||||
break;
|
||||
if (typeof input === 'string') {
|
||||
switch (splitOperatorType) {
|
||||
case 'symbol':
|
||||
array = input.split(splitSeparator);
|
||||
break;
|
||||
case 'regex':
|
||||
array = input
|
||||
.split(new RegExp(splitSeparator))
|
||||
.filter((item) => item !== '');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
array = input;
|
||||
}
|
||||
|
||||
// Trim items if required
|
||||
|
||||
Reference in New Issue
Block a user