mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
refactor: review related changes
This commit is contained in:
@@ -1,33 +1,9 @@
|
||||
import { itemCounter } from '@utils/string';
|
||||
|
||||
export type SplitOperatorType = 'symbol' | 'regex';
|
||||
export type DisplayFormat = 'count' | 'percentage' | 'total';
|
||||
export type SortingMethod = 'count' | 'alphabetic';
|
||||
|
||||
// Function that takes the array as arg and returns a dict of element occurrences and handle the ignoreItemCase
|
||||
function dictMaker(
|
||||
array: string[],
|
||||
ignoreItemCase: boolean
|
||||
): { [key: string]: number } {
|
||||
const dict: { [key: string]: number } = {};
|
||||
for (const item of array) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Function that sorts the dict created with dictMaker based on the chosen sorting method
|
||||
function dictSorter(
|
||||
dict: { [key: string]: number },
|
||||
@@ -121,7 +97,7 @@ export function TopItemsList(
|
||||
}
|
||||
|
||||
// Transform the array into dict
|
||||
const unsortedDict = dictMaker(array, ignoreItemCase);
|
||||
const unsortedDict = itemCounter(array, ignoreItemCase);
|
||||
|
||||
// Sort the list if required
|
||||
const sortedDict = dictSorter(unsortedDict, sortingMethod);
|
||||
|
||||
Reference in New Issue
Block a user