EvanHahn / HumanizeDuration.js

361000 becomes "6 minutes, 1 second"
https://evanhahn.github.io/HumanizeDuration.js/
The Unlicense
1.65k stars 175 forks source link

Make Humanizers option to be able to take a function with current value #74

Closed mickeyvip closed 7 years ago

mickeyvip commented 9 years ago

Hi and thank you.

I have a situation where I need to decide if to round or not the value based on... the value:

var viewValue = humanizeDuration(x, { round: x > 1000 });

I use it in many places so it makes sense to create a Humanizer similar to:

var myHumanizer = humanizeDuration.humanizer({
  language: "en",
  round: function(value) {
    return value > 1000;
  }
});
EvanHahn commented 9 years ago

I'd be hesitant to do this instead of #73. You could solve it with something like this:

humanizeDuration(x, { round: value > 1000 })
mickeyvip commented 9 years ago

Sorry for the typo in the title.

I am currently doing what you are proposing (the curly braces got lost, because I copied the example from CoffeeScript), but if I do it in many places, it would be shorter to create 1 humanazer and use it instead.

EvanHahn commented 8 years ago

Feel free to submit a pull request for this.

EvanHahn commented 7 years ago

This library is in maintenance mode, so I won't be adding new features, sadly. I'm going to close this issue. See #120 for more.