Sencha Documentation

General purpose inflector class that pluralizes, singularizes and ordinalizes words. Sample usage:

//turning singular words into plurals
Ext.util.Inflector.pluralize('word'); //'words'
Ext.util.Inflector.pluralize('person'); //'people'
Ext.util.Inflector.pluralize('sheep'); //'sheep'

//turning plurals into singulars
Ext.util.Inflector.singularize('words'); //'word'
Ext.util.Inflector.singularize('people'); //'person'
Ext.util.Inflector.singularize('sheep'); //'sheep'

//ordinalizing numbers
Ext.util.Inflector.ordinalize(11); //"11th"
Ext.util.Inflector.ordinalize(21); //"21th"
Ext.util.Inflector.ordinalize(1043); //"1043rd"

Customization

The Inflector comes with a default set of US English pluralization rules. These can be augmented with additional rules if the default rules do not meet your application's requirements, or swapped out entirely for other languages. Here is how we might add a rule that pluralizes "ox" to "oxen":

Ext.util.Inflector.plural(/^(ox)$/i, "$1en");

Each rule consists of two items - a regular expression that matches one or more rules, and a replacement string. In this case, the regular expression will only match the string "ox", and will replace that match with "oxen". Here's how we could add the inverse rule:

Ext.util.Inflector.singular(/^(ox)en$/i, "$1");

Note that the ox/oxen rules are present by default.

Methods

 
classify( String word ) : String
Returns the correct Model name for a given string. Mostly used internally by the data package
Returns the correct Model name for a given string. Mostly used internally by the data package

Parameters

  • word : String
    The word to classify

Returns

  • String   The classified version of the word
 
Removes all registered pluralization rules
Removes all registered pluralization rules
 
Removes all registered singularization rules
Removes all registered singularization rules
 
isUncountable( String word ) : Boolean
Returns true if the given word is uncountable (the word is its own singular and plural form - e.g. sheep, fish)
Returns true if the given word is uncountable (the word is its own singular and plural form - e.g. sheep, fish)

Parameters

  • word : String
    The word to test

Returns

  • Boolean   True if the word is uncountable
 
ordinalize( Number number ) : String
Ordinalizes a given number by adding a prefix such as 'st', 'nd', 'rd' or 'th' based on the last digit of the number...
Ordinalizes a given number by adding a prefix such as 'st', 'nd', 'rd' or 'th' based on the last digit of the number. 21 -> 21st, 22 -> 22nd, 23 -> 23rd, 24 -> 24th etc

Parameters

  • number : Number
    The number to ordinalize

Returns

  • String   The ordinalized number
 
plural( RegExp matcher, String replacer ) : Void
Adds a new pluralization rule to the Inflector. See the intro docs for more information
Adds a new pluralization rule to the Inflector. See the intro docs for more information

Parameters

  • matcher : RegExp
    The matcher regex
  • replacer : String
    The replacement string, which can reference matches from the matcher argument

Returns

  • Void
 
pluralize( String word ) : String
Returns the pluralized form of a word (e.g. Ext.util.Inflector.pluralize('word') returns 'words')
Returns the pluralized form of a word (e.g. Ext.util.Inflector.pluralize('word') returns 'words')

Parameters

  • word : String
    The word to pluralize

Returns

  • String   The pluralized form of the word
 
singular( RegExp matcher, String replacer ) : Void
Adds a new singularization rule to the Inflector. See the intro docs for more information
Adds a new singularization rule to the Inflector. See the intro docs for more information

Parameters

  • matcher : RegExp
    The matcher regex
  • replacer : String
    The replacement string, which can reference matches from the matcher argument

Returns

  • Void
 
singularize( String word ) : String
Returns the singularized form of a word (e.g. Ext.util.Inflector.singularize('words') returns 'word')
Returns the singularized form of a word (e.g. Ext.util.Inflector.singularize('words') returns 'word')

Parameters

  • word : String
    The word to singularize

Returns

  • String   The singularized form of the word