tlux / file_size

A file size calculator, parser and formatter written in Elixir
MIT License
6 stars 1 forks source link

Seems like the Parser doesn't utilize the config #7

Closed sitch closed 4 years ago

sitch commented 4 years ago

adding:

config :file_size, :symbols, %{
  b: "B",
  kb: "k",
  mb: "M",
  gb: "G",
  tb: "T"
}

Still fails for

iex> FileSize.parse("1 k")                                  
{:error, %FileSize.ParseError{reason: :unit, value: "1 k"}}
tlux commented 4 years ago

Currently, this is by design. Because, when you have multiple applications using file_size in the same project, you would be able globally override the parser behavior for all applications which can lead to unexpected behavior.

However, for your use case it would be possible to introduce FileSize.parse/2 (similar to FileSize.format/2) so we could pass some options to the parser, for example:

FileSize.parse("1 k", symbols: %{kb: "k", m: "M"})

You are very welcome to open a pull request. :) Closing this for now.