This is a CFML (Lucee/Cold Fusion) component which provides the ability to transform words from singular to plural (and back again), capitalises, PascelCase or CamelCases and humanises.
It is based on a combination of inflector clases openly available under MIT licence.
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
sto the end of the singlar form. - Special cases: specific cases the occur with some word forms, such
as
analysistoanalyses. - Irregulars: where the singluar/plural don't follow standard rules,
e.g.
personbecomespeople. - Uncountables: words which are the same in both singular and plural
form, e.g.
rice,money.
-
capitalise()capitalises the first character in a string:testbecomesTest -
camelCase()converts a given string to camelCase, with all non-alphanumeric characters stripped:camel_casebecomescamelCase -
PascelCase()converts a given string to PascelCase, with all non-alphanumeric characters stripped:pascal_casebecomesPascelCase -
variablise()converts a string to an underscore-separated list:PascelCaseorcamelCasebecomescamel_case -
humanise()converts a string to a human-readable form:PascelCaseorCamelCasebecomesCamel Case -
pad()pads a given string with spaces or other characters. -
isPluralreturns true if the word is plural -
isSingularreturns if the word is singular
See test/tests/InflectorTest.cfc for how other strings are handled.
inflector-cfml is the results of a combination of several inflector libraries on github including:
- coldfusion-inflector was originally developed by Tim Blair
- doctrine inflector
Released under the MIT license as detailed in the LICENSE file that should be distributed with this library; the source code is freely available.