Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created August 26, 2011 10:32
Show Gist options
  • Select an option

  • Save mindscratch/1173160 to your computer and use it in GitHub Desktop.

Select an option

Save mindscratch/1173160 to your computer and use it in GitHub Desktop.
Inflector is a small library for working with strings.
// I found this via the following URL https://www.jig.com/static/js/inflector.js?v=600c7 on 08/26/2011
// and thought it was pretty cool, however, I haven't found a Tasty Labs JS page or some other official
// place where it has been released, so I thought I'd save a copy here for now.
// Copyright 2011 Tasty Labs
//
// Inflector is a small library for working with strings.
window.Inflector = {
pluralize : function(count, s, includeCount) {
var c = includeCount ? count + ' ' : '';
if (count == 1) return c + s;
if (s == 'this') return c + 'these';
if (s == 'person') return c + 'people';
if (s.match(/day$/i)) return c + s.replace(/day$/i, 'days');
if (s.match(/y$/i)) return c + s.replace(/y$/i, 'ies');
return c + s + 's';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment