For up to date documentation and features, visit http://docs.sencha.com/ext-js/4-0

## Sencha Documentation

# Ext.util.Inflector

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.

Defined By

### Methods

Ext.util.Inflector
view source
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

Ext.util.Inflector
view source
clearPlurals : void

Removes all registered pluralization rules

Removes all registered pluralization rules

### Returns

- void

Ext.util.Inflector
view source
clearSingulars : void

Removes all registered singularization rules

Removes all registered singularization rules

### Returns

- void

Ext.util.Inflector
view source
isTransnumeral( String word) : Boolean

Returns true if the given word is transnumeral (the word is its own singular and plural form - e.g. sheep, fish)

Returns true if the given word is transnumeral (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 transnumeral

Ext.util.Inflector
view source
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

Ext.util.Inflector
view source
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

Ext.util.Inflector
view source
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

Ext.util.Inflector
view source
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

Ext.util.Inflector
view source
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