This is a ColdFusion component which provides the ability to transform words from singular to plural (and back again), capitalises, CamelCases and humanises. It is based on the Ruby on Rails ActiveSupport::Inflector class.
Copy the Inflector.cfc
file somewhere CF can find it, and then:
<cfset inflector = createobject("component", "Inflector")>
<cfset plural = inflector.pluralise("person")> <!--- people --->
<cfset singular = inflector.singularise("zombies")> <!--- zombie --->
Pluralisation and singularisation both take into account:
- Standard grammar rules: the plural is formed by adding
s
to the end of the singlar form. - Special cases: specific cases the occur with some word forms, such
as
analysis
toanalyses
. - Irregulars: where the singluar/plural don't follow standard rules,
e.g.
person
becomespeople
. - Uncountables: words which are the same in both singular and plural
form, e.g.
rice
,money
.
capitalise
capitalises the first character in a string:test
becomesTest
CamelCase
converts a given string to CamelCase, with all non-alphanumeric characters stripped:camel_case
becomesCamelCase
variablise
converts a string to an underscore-separated list:CamelCase
becomescamel_case
humanise
converts a string to a human-readable form:CamelCase
becomesCamel Case
pad
pads a given string with spaces.
See test/tests/InflectorTest.cfc
for how other strings are handled.
coldfusion-inflector was developed by Tim Blair and is released under the MIT license as detailed in the LICENSE file that should be distributed with this library; the source code is freely available.