X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6a7e4474cba9d8be4b2ec445e10f1691f7277c50..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/docs/api/Ext.util.Inflector.html diff --git a/docs/api/Ext.util.Inflector.html b/docs/api/Ext.util.Inflector.html new file mode 100644 index 00000000..b8b87082 --- /dev/null +++ b/docs/api/Ext.util.Inflector.html @@ -0,0 +1,148 @@ +Ext.util.Inflector | Ext JS 4.0 Documentation +
For up to date documentation and features, visit +http://docs.sencha.com/ext-js/4-0

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.

+ +
Defined By

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

+

Returns

  • void    +
 

Removes all registered singularization rules

+

Removes all registered singularization rules

+

Returns

  • void    +
 

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

    +
 
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    +
 

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

    +
\ No newline at end of file