Created
August 26, 2011 10:32
-
-
Save mindscratch/1173160 to your computer and use it in GitHub Desktop.
Inflector is a small library for working with strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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