Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


A simple utility library for making the web more humane. #hubspot-open-source

Subscribe to updates I use humanize

Statistics on humanize

Number of watchers on Github 716
Number of open issues 19
Average time to close an issue 2 months
Main language CoffeeScript
Average time to merge a PR 4 days
Open pull requests 14+
Closed pull requests 7+
Last commit about 4 years ago
Repo Created over 7 years ago
Repo Last Updated about 2 years ago
Size 706 KB
Organization / Authorhubspot
Latest Releasev1.5.0
Page Updated
Do you use humanize? Leave a review!
View open issues (19)
View humanize activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating humanize for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Humanize Plus

npm version build status npm downloads

A simple utility library for making the web more humane.

Getting Started

Humanize Plus is available via node package manager.

npm install humanize-plus

Or download the minified version or the full version.

In your web page:

<script src="public/humanize.min.js"></script>
var capitalized = Humanize.capitalize("ten tiny ducklings.")
// "Ten tiny ducklings."

In your node package.json:

"dependencies": {
  "humanize-plus": "^1.7.0"

For recent changes, see the changelog.

API Methods



Formats a number to a human-readable string. Localize by overriding the precision, thousand and decimal arguments.

Humanize.formatNumber(123456789, 2)
// "123,456,789.00"

Converts an integer to a string containing commas every three digits.

// "123,456,789"
intcomma - DEPRECATED - This method will not be present in the next major version.

Alias for intComma

intword - DEPRECATED - This method will not be present in the next major version.

Converts a large integer to a friendly text representation. This method is now a thin wrapper around compactInteger

Humanize.intword(num, ch, de) === Humanize.compactInteger(num, de)

Humanize.intword(123456789, 'nopnopnopnop', 1)
// "123.5M"

Humanize.intword(123456789, 'this is a nop', 3)
// "123.457M"

Humanize.intword(10, 'still a nop', 1)
// "10"

Converts an integer into its most compact representation. Decimal precision is ignored for all integers, n, such that abs(n) < 1000.

Humanize.compactInteger(123456789, 1)
// "123.5M"

// Switch to scientific notation for trillons, because no one knows those abbreviations.
Humanize.compactInteger(-7832186132456328967, 4)
// "-7.8322x10^18"

Humanize.compactInteger(-100, 2)
// "-100"

Bounds a value from above. Modified values have customizable ending strings ('+' by default)

Humanize.boundedNumber(110, 100)
// "100+"

Humanize.boundedNumber(50, 100)
// "50"
truncatenumber - DEPRECATED - This method will not be present in the next major version.

Alias for boundedNumber


Converts an integer to its ordinal as a string.

// "22nd"

Interprets numbers as occurences. Also accepts an optional array/map of overrides.

for (i=0; i<5; i++) {
  Humanize.times(i, {"4": "too many"});
  // Bonus!
  if (i === 1) {
// never
// once
// 1.1 times
// twice
// 3 times
// too many times

Matches a pace (value and interval) with a logical time frame. Very useful for slow paces.

second = 1000
week = 6.048e8
decade = 3.156e11

Humanize.pace(1.5, second, "heartbeat")
// Approximately 2 heartbeats per second

Humanize.pace(4, week)
// Approximately 4 times per week

Humanize.pace(1, decade, "life crisis")
// Less than 1 life crisis per week

Formats the value like a 'human-readable' file size (i.e. '13 KB', '4.1 MB', '102 bytes', etc).

Humanize.fileSize(1024 * 20)
// "20 Kb"

Humanize.fileSize(1024 * 2000)
// "1.95 Mb"

Humanize.fileSize(Math.pow(1000, 4))
// "931.32 Gb"
filesize - DEPRECATED - This method will not be present in the next major version.

Alias for fileSize


Returns the plural version of a given word if the value is not 1. The default suffix is 's'.

Humanize.pluralize(1, "duck")
// "duck"

Humanize.pluralize(3, "duck")
// "ducks"

Humanize.pluralize(3, "duck", "duckies")
// "duckies"



Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("").

Humanize.truncate('long text is good for you')
// "long text is good for you"

Humanize.truncate('long text is good for you', 19)
// "long text is goo..."

Humanize.truncate('long text is good for you', 19, '... etc')
// "long text is... etc"

Truncates a string after a certain number of words.

Humanize.truncateWords('long text is good for you', 5)
// "long text is good for ..."
truncatewords - DEPRECATED - This method will not be present in the next major version.

Alias for truncateWords

nl2br and br2nl

Flexible conversion of <br/> tags to newlines and vice versa.

// Use your imagination

Capitalizes the first letter in a string, optionally downcasing the tail.

Humanize.capitalize("some boring string")
// "Some boring string"

// "WHoOaA!"

Humanize.capitalize("wHoOaA!", true)
// "Whooaa!"

Captializes the first letter of every word in a string.

Humanize.capitalizeAll("some boring string")
// "Some Boring String"

Intelligently capitalizes eligible words in a string and normalizes internal whitespace.

Humanize.titleCase("some of a boring string")
// "Some of a Boring String"

Humanize.titleCase("cool the          iTunes cake, O'Malley!")
// "Cool the iTunes Cake, O'Malley!"
titlecase - DEPRECATED - This method will not be present in the next major version.

Alias for titleCase



Converts a list of items to a human readable string with an optional limit.

items = ['apple', 'orange', 'banana', 'pear', 'pineapple']

// "apple, orange, banana, pear, and pineapple"

Humanize.oxford(items, 3)
// "apple, orange, banana, and 2 others"

// Pluralizes properly too!
Humanize.oxford(items, 4)
// "apple, orange, banana, pear, and 1 other"

Humanize.oxford(items, 3, "and some other fruits")
// "apple, orange, banana, and some other fruits"

Describes how many times an item appears in a list

aznPics = [
bigfootPics = []

"Instagrammers " + Humanize.frequency(aznPics, "took pictures of food")
// "Instagrammers took pictures of food 3 times"

"Bigfoot " + Humanize.frequency(bigfootPics, "took pictures of food")
// "Bigfoot never took pictures of food"

Utility methods


Fixes binary rounding issues (eg. (0.615).toFixed(2) === 0.61).

Humanize.toFixed(0.615, 2)
// "0.62"

Ensures precision value is a positive integer.

// 232

Important notes

Please don't edit files in the dist subdirectory as they are generated through compilation. You'll find source code in the src subdirectory!


npm run install && npm run build

And that's it!

The project will compile the CoffeeScript files into the dist subdirectory.


npm run test


Copyright (c) 2013-2016 HubSpotDev Licensed under the MIT license.

humanize open issues Ask a question     (View All Issues)
  • over 3 years Should check for 'undefined' or `null` parameter values
  • over 3 years Humanize.truncateWords returns null when input has less number of words
  • over 3 years Error in Firefox
  • almost 4 years TypeScript definitions
  • about 4 years Rewrite functions as ES6 modules
humanize open pull requests (View All Pulls)
  • KB should be kB
  • Added #truncateNearestWord
  • update some versions
  • Add percision parameter to fileSize
  • fix #67
  • Make it possible to customize the arguments of formatNumber
  • Add optional conjunction parameter to oxford
  • Introduction rewrite
  • Using main from dist folder; updated version.
  • Have ordinal return 0th instead of 0
  • Fix "SyntaxError: missing = in const declaration" in Firefox. fixes #83
  • null issue with truncateWords fixes #84, added tests
  • update readme to reflect coffeescript was replaced with ecmascript
  • Add Typescript Definition
humanize questions on Stackoverflow (View All Questions)
  • Is it possible to Humanize TimeSpan to years with Humanizer?
  • Django humanize outside of template?
  • How to humanize duration in angularjs?
  • Humanize uppercase name with hyphenated last name
  • Humanize a string in JavaScript
  • How can I format and humanize a video chunk duration using moment.js?
  • How can I humanize this complete duration in moment.js / javascript
  • Moment.js : change the default humanize() behavior
  • Humanize numbers with python
  • Using Play framework with Scala, how can I humanize a Json Validation message?
  • humanize in django/python, how to translate
  • How to humanize child input in Rails?
  • javascript custom humanize filter
  • How do i humanize variables like A1+ and A1- (list of blood groups)
  • Is there a way to have a custom humanize result for certain symbols?
  • How to display "x days ago" type time using Humanize in Django template?
  • Custom filesize format with Python Humanize?
  • Rails how to call helpers such as .humanize on an attribute of collection_select
  • humanize "naturaltime" issue
  • Backbone.js equivalent of django humanize - int.word and int.comma - using underscore.string
  • Getting django's humanize working on App Engine
  • Inflector::humanize($key) converts Date of joining TO Date Of Joining
  • Rails - Humanize attribute globally
  • Rails datetime interval humanize
  • "TemplateSyntaxError: 'humanize' is not a valid tag library:" in DJango
  • Humanize rails select helper
  • Humanize attributes with Mongoid?
  • Is there an easy way to humanize string in collection_select?
  • Does rails have an opposite of 'humanize' for strings?
  • How to display "This many months ago" in Django using Humanize?
humanize list of languages used
humanize latest release notes
v1.5.0 v1.5.0

Drop support for node v0.6 and update compactInteger()

v1.4.2 v1.4.2

Couple of bug fixes and additions, primarily for our node.js friends. Also starting to deprecate a couple of methods in preparation for v2.

Other projects in CoffeeScript