Skip to content

Commit 9bb8853

Browse files
Build changes
1 parent abf929a commit 9bb8853

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

general.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function tryParseJSON(str: string): any {
103103
}
104104
}
105105

106-
export function formatBytes(bytes, decimals = 2) {
106+
export function formatBytes(bytes: number, decimals = 2) {
107107
if (bytes === 0) return '0 Bytes';
108108
const dm = decimals < 0 ? 0 : decimals;
109109
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
@@ -115,25 +115,26 @@ export function formatBytes(bytes, decimals = 2) {
115115
export type enumToArrayOptions = {
116116
caseType?: caseType;
117117
prefix?: string;
118-
nameFunction?: (name: string) => string;
118+
nameFunction: (name: string) => string;
119119
}
120120

121-
export function enumToArray(e: Object, options: enumToArrayOptions = null): any[] {
121+
export function enumToArray(e: Object, options: enumToArrayOptions | null = null): any[] {
122122
const arr = Object.values(e);
123123
if (!options) return sortByEnumPos(e, arr);
124124
let func;
125-
if (options.caseType == caseType.LOWER) func = (x) => x.toLowerCase();
126-
else if (options.caseType == caseType.UPPER) func = (x) => x.toUpperCase();
125+
if (options.caseType == caseType.LOWER) func = (x: any) => x.toLowerCase();
126+
else if (options.caseType == caseType.UPPER) func = (x: any) => x.toUpperCase();
127127
else if (options.caseType == caseType.CAPITALIZE_FIRST) func = capitalizeFirst;
128128
else if (options.caseType == caseType.CAPITALIZE_FIRST_PER_WORD) func = capitalizeFirstPerWord;
129129

130130
if (func) return enumToArray(e, { prefix: options.prefix, nameFunction: func });
131131
if (!options.nameFunction) return sortByEnumPos(e, arr.map(x => ({ name: options.prefix + x, value: x })));
132+
132133
return sortByEnumPos(e, arr.map(x => ({ name: (options.prefix ? options.prefix : "") + options.nameFunction(x), value: x })));
133134
}
134135

135-
function sortByEnumPos(e: Object, arr: any[]) {
136-
const order = [];
136+
function sortByEnumPos(e: any, arr: any[]) {
137+
const order: string[] = [];
137138
for (let key in e) {
138139
order.push(key);
139140
}

0 commit comments

Comments
 (0)