jofftiquez / vue-morphling

Vue filters and directives collection.

Home Page:https://jofftiquez.github.io/vue-morphling/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FR] Option for morph-file-size to specify decimal places

straurob opened this issue · comments

As a user of the morph-file-size filter I'd like to add fa ormatting option/directive on how many digits shall be rendered for the decimal place.

Example
<code>{{ 1048576 | morph-file-size }}</code> renders to 1.0 Mb.

I'd like this to be rendered as 1 Mb so it'd be nice to have something like:

<code>{{ 1048576 | morph-file-size(0) }}</code> renders to 1 Mb.
<code>{{ 1048576 | morph-file-size(2) }}</code> renders to 1.00 Mb.

@straurob I understand. I'll label this as enhancement and feature request. However, I can't promise an ETA at the moment, because I am currently very busy. I will keep you posted on this issue.

I had a look at the implementation and it turned out that the underlying library filesize.js library is not maintained and lacks a lot of options.

Maybe it would be an idea refactoring this to use https://github.com/avoidwork/filesize.js instead? This library already provides a lot of options and is under active maintainance.

I'll open a PR...

Hi @straurob kindly try vue-morphling@1.1.0 just add the option { base: 0 }, like so: {{ 1048576 | morph-file-size({ base: 0 }) }}

I didn't see your comment right away. We had the same idea haha. I upgraded it to use filesize instead of filesize.js. Now all options are available. Please kindly let me know once you tried it. Thanks.

Glad I saw your comment just in time as I already started working on a PR :-) Passing in the options from filesize works.

Thanks a lot for the quick fix.

Gotcha buddy! @straurob