Live data from Hacker News

Humanize: my first open source package, mostly a rewrite

github.com

1–10 of 13 posts

Re: Humanize: my first open source package, mostly a rewrite

#2
You should check out the 'quantification' features of this Python lib called Pattern: http://www.clips.ua.ac.be/pages/pattern-en

  >>> from pattern.en import quantify
  >>> print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken'])
  >>> print quantify('carrot', amount=1000)
  >>> print quantify({'carrot': 100, 'parrot': 20})
 
  several chickens, a pair of geese and a duck
  hundreds of carrots
  dozens of carrots and a score of parrots
This is useful functionality to include. It's practically cheating to port Python to JavaScript so it shouldn't be hard to adapt the relevant parts of the code to your project. (Well, depending on how much of it depends on the pluralization/singularization portions of Pattern.)

Re: Humanize: my first open source package, mostly a rewrite

#3

You should check out the 'quantification' features of this Python lib called Pattern: http://www.clips.ua.ac.be/pages/pattern-en >>> from pattern.en import quantify >>> print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken']) >>> print quantify('carrot', amount=1000) >>> print quantify({'carrot': 100, 'parrot': 20}) several chickens, a pair of geese and a duck hundreds of carrots dozens of carrots…

Thanks for the suggestion. I'll look into it

Re: Humanize: my first open source package, mostly a rewrite

#6

  humanize.filesize(1234567890); // '1.15 Gb'
You should use a capital 'B' for byte filesizes to avoid confusion with 'b'its.

And, you might want to let the user choose between decimal or binary prefixes (rather than the 'kilo' redefinition).

1234567890 bytes is 1.23 GB in pedantic application of SI naming, as used by MacOS and Ubuntu GUIs after a certain point.

1234567890 bytes is 1.15 GiB by the IEC standard for base-2 units, which is also "1.15 GB" by the older we-hope-context-makes-things-clear tradition.

See the approach of python humanize for one way to parameterize the output:

http://pypi.python.org/pypi/humanize

And see the Ubuntu Units Policy for some reasonable suggestions for when to use which kinds of units:

https://wiki.ubuntu.com/UnitsPolicy

Re: Humanize: my first open source package, mostly a rewrite

#7

You should check out the 'quantification' features of this Python lib called Pattern: http://www.clips.ua.ac.be/pages/pattern-en >>> from pattern.en import quantify >>> print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken']) >>> print quantify('carrot', amount=1000) >>> print quantify({'carrot': 100, 'parrot': 20}) several chickens, a pair of geese and a duck hundreds of carrots dozens of carrots…

That's awesome. I needed that last week ironically.

Thanks for posting.

Re: Humanize: my first open source package, mostly a rewrite

#8
post #7

You should check out the 'quantification' features of this Python lib called Pattern: http://www.clips.ua.ac.be/pages/pattern-en >>> from pattern.en import quantify >>> print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken']) >>> print quantify('carrot', amount=1000) >>> print quantify({'carrot': 100, 'parrot': 20}) several chickens, a pair of geese and a duck hundreds of carrots dozens of carrots…

That's awesome. I needed that last week ironically. Thanks for posting.

Ironically?

Re: Humanize: my first open source package, mostly a rewrite

#10
post #5

This is nice if you just want a really really lightweight date humanizer with no i18n support. If you want a full-blown date/time parser/formatter/humanizer, I highly recommend moment.js http://momentjs.com/

Thanks, I had no idea momentjs existed. It's a lot fancier, and likely less buggy ;)
Post reply on HN