@@ -103,7 +103,7 @@ export function tryParseJSON(str: string): any {
103
103
}
104
104
}
105
105
106
- export function formatBytes ( bytes , decimals = 2 ) {
106
+ export function formatBytes ( bytes : number , decimals = 2 ) {
107
107
if ( bytes === 0 ) return '0 Bytes' ;
108
108
const dm = decimals < 0 ? 0 : decimals ;
109
109
const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
@@ -115,25 +115,26 @@ export function formatBytes(bytes, decimals = 2) {
115
115
export type enumToArrayOptions = {
116
116
caseType ?: caseType ;
117
117
prefix ?: string ;
118
- nameFunction ? : ( name : string ) => string ;
118
+ nameFunction : ( name : string ) => string ;
119
119
}
120
120
121
- export function enumToArray ( e : Object , options : enumToArrayOptions = null ) : any [ ] {
121
+ export function enumToArray ( e : Object , options : enumToArrayOptions | null = null ) : any [ ] {
122
122
const arr = Object . values ( e ) ;
123
123
if ( ! options ) return sortByEnumPos ( e , arr ) ;
124
124
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 ( ) ;
127
127
else if ( options . caseType == caseType . CAPITALIZE_FIRST ) func = capitalizeFirst ;
128
128
else if ( options . caseType == caseType . CAPITALIZE_FIRST_PER_WORD ) func = capitalizeFirstPerWord ;
129
129
130
130
if ( func ) return enumToArray ( e , { prefix : options . prefix , nameFunction : func } ) ;
131
131
if ( ! options . nameFunction ) return sortByEnumPos ( e , arr . map ( x => ( { name : options . prefix + x , value : x } ) ) ) ;
132
+
132
133
return sortByEnumPos ( e , arr . map ( x => ( { name : ( options . prefix ? options . prefix : "" ) + options . nameFunction ( x ) , value : x } ) ) ) ;
133
134
}
134
135
135
- function sortByEnumPos ( e : Object , arr : any [ ] ) {
136
- const order = [ ] ;
136
+ function sortByEnumPos ( e : any , arr : any [ ] ) {
137
+ const order : string [ ] = [ ] ;
137
138
for ( let key in e ) {
138
139
order . push ( key ) ;
139
140
}
0 commit comments