avoidwork / filesize.js

JavaScript library to generate a human readable String describing the file size
https://filesizejs.com
BSD 3-Clause "New" or "Revised" License
1.61k stars 97 forks source link

fixup: Add interface for filesize options object #171

Closed aitk closed 1 year ago

aitk commented 1 year ago

This will provide consistency between filesize and partial function options.

This will also fix an issue I had while utilising the library where I want to validate the options supplied to a generic formatter function for example here is my implementation.

interface SomeNumberOptions = {
   compact: bool
}

const getFormatter = (type: string): (value: any, options: SomeNumberOptions | FileSizeOptions) => string {
    const formatters = {
         number: (value: number, options: SomeNumberOptions): string => {...}
         bytes: (value: number, options: FileSizeOptions): string => {...}
    }

    return formatters[type]
}

I've also updated some options from strings to unions.

avoidwork commented 1 year ago

This is 10.0.8