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 } {
|
): { [key: string]: number } {
|
||||||
const dict: { [key: string]: number } = {};
|
const dict: { [key: string]: number } = {};
|
||||||
for (const item of array) {
|
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;
|
dict[key] = (dict[key] || 0) + 1;
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
@@ -74,21 +87,27 @@ export function TopItemsList(
|
|||||||
sortingMethod: SortingMethod,
|
sortingMethod: SortingMethod,
|
||||||
displayFormat: DisplayFormat,
|
displayFormat: DisplayFormat,
|
||||||
splitSeparator: string,
|
splitSeparator: string,
|
||||||
input: string,
|
input: string | string[],
|
||||||
deleteEmptyItems: boolean,
|
deleteEmptyItems: boolean,
|
||||||
ignoreItemCase: boolean,
|
ignoreItemCase: boolean,
|
||||||
trimItems: boolean
|
trimItems: boolean
|
||||||
): string {
|
): string {
|
||||||
|
if (!input) return '';
|
||||||
|
|
||||||
let array: string[];
|
let array: string[];
|
||||||
switch (splitOperatorType) {
|
if (typeof input === 'string') {
|
||||||
case 'symbol':
|
switch (splitOperatorType) {
|
||||||
array = input.split(splitSeparator);
|
case 'symbol':
|
||||||
break;
|
array = input.split(splitSeparator);
|
||||||
case 'regex':
|
break;
|
||||||
array = input
|
case 'regex':
|
||||||
.split(new RegExp(splitSeparator))
|
array = input
|
||||||
.filter((item) => item !== '');
|
.split(new RegExp(splitSeparator))
|
||||||
break;
|
.filter((item) => item !== '');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
array = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim items if required
|
// Trim items if required
|
||||||
|
|||||||
Reference in New Issue
Block a user