---
title: "Building More Humane Software with humanize.js"
date: 2013-02-05
authors: [bryan-ash]
topics: [Frontend]
canonical: https://product.hubspot.com/blog/humanize-js-making-the-internet-more-humane
cover:
  scene: humanize-js-making-the-internet-more-humane
  alt: "A toy robot's speech bubble full of braces and digits is tidied into groups with orange commas and an ellipsis, and the kid listening waves."
---

As front-end developers, we're always looking to make the software we create as friendly as possible for actual humans to use.

![Hand-lettered code: a String.format call whose format string is an unreadable jumble of braces, zeros and hash signs.](/assets/blog/humanize-js-making-the-internet-more-humane/msfillustration.png)

We're frequently called on to transform all kinds of data — currencies, dates, times, arrays, and objects — into human-friendly versions for display. We'll often end up writing one-off functions for these small tasks. Which can be deceptively simple when you start out, so it doesn't _feel_ like you're creating a maintenance burden for yourself, but in fact, you are.

Sometimes we can get away with using built-in methods, like `Date.parse()` or some fancy type conversion. But, that often doesn't go far enough. Simple string concatentation just doesn't cut it.

So here at HubSpot we improved on the best parts of current formatting libraries to create [Humanize](https://github.com/hubspot/humanize). This library has been helpful in creating a consistent, _human_ voice throughout our applications. It has a simple API, and it's both performant and well tested.

## What Is It?

Humanize is an **"object to string"** formatting library. Unlike other libraries that only let you format strings, Humanize helps you convert different types of data to human-readable text, like turning an array into a comma-separated list ([oxford comma](http://en.wikipedia.org/wiki/Serial_comma) optional).

### Examples:

```
Humanize.dictionary({apples: 'red', banana: 'yellow'}) // 'apples are red, bananas are yellow'
```

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

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

```
Humanize.ordinal(22) // "22nd"
```

```
Humanize.filesize(Math.pow(1000, 4)) // "931.32 Gb"
```

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

Naturally, Humanize also includes optimized versions of basic string formatting methods (`truncate`, `pluralize`, etc.), but there are (intentionally) no date formatting methods. For that, we highly recommend checking out [moment.js](http://momentjs.com/).

Humanize ([github](https://github.com/hubspot/humanize)) is written in [CoffeeScript](http://coffeescript.org/) (because we **love&#x20;**&#x43;offeeScript) and compiled using [Grunt](http://gruntjs.com/), complete with Jasmine specs. As always, send us a pull request if you have any ideas for improvement. Or if you're just a regular human (that is, not a developer), please leave a comment on this post and let us know other ways we can make our output more human.

Image via [masterdata.se](http://www.masterdata.se/r/string_format_for_javascript/)

_This is part of a series of posts on a bunch of new open source software released by HubSpot developers._
