Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

94 lines (67 sloc) 12.114 kB
<!DOCTYPE html> <html> <head> <title>string_extensions.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="default_inflections.html"> default_inflections.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="inflections.html"> inflections.coffee </a> <a class="source" href="methods.html"> methods.coffee </a> <a class="source" href="number_extensions.html"> number_extensions.coffee </a> <a class="source" href="string_extensions.html"> string_extensions.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> string_extensions.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">inflect = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;../inflect&#39;</span><span class="p">)</span>
<span class="nv">enableStringExtensions = </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Returns the plural form of the word in the string.</p>
<h3>Examples</h3>
<pre><code>"post".pluralize() # =&gt; "posts"
"octopus".pluralize() # =&gt; "octopi"
"sheep".pluralize() # =&gt; "sheep"
"words".pluralize() # =&gt; "words"
"CamelOctopus".pluralize() # =&gt; "CamelOctopi"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">pluralize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">pluralize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The reverse of <tt>pluralize</tt>, returns the singular form of a word in a string.</p>
<h3>Examples</h3>
<pre><code>"posts".singularize() # =&gt; "post"
"octopi".singularize() # =&gt; "octopus"
"sheep".singularize() # =&gt; "sheep"
"word".singularize() # =&gt; "word"
"CamelOctopi".singularize() # =&gt; "CamelOctopus"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">singularize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">singularize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>By default, <tt>camelize</tt> converts strings to UpperCamelCase. If the argument to <tt>camelize</tt>
is set to <tt>false</tt> then <tt>camelize</tt> produces lowerCamelCase.</p>
<h3>Examples</h3>
<pre><code>"active_record".camelize() # =&gt; "ActiveRecord"
"active_record".camelize(false) # =&gt; "activeRecord"
</code></pre>
<p>As a rule of thumb you can think of <tt>camelize</tt> as the inverse of <tt>underscore</tt>,
though there are cases where that does not hold:</p>
<pre><code>"SSLError".underscore().camelize() # =&gt; "SslError"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">camelize = </span><span class="nf">(first_letter_in_uppercase = true) -&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">camelize</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">first_letter_in_uppercase</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Converts the first character to uppercase and the remainder to lowercase.</p>
<h3>Examples</h3>
<pre><code>'über'.capitalize() # =&gt; "Über"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">capitalize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">capitalize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Converts the first character to lowercase and leaves the remainder intact.</p>
<h3>Examples</h3>
<pre><code>'über'.capitalize() # =&gt; "Über"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">decapitalize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">decapitalize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Capitalizes all the words and replaces some characters in the string to create
a nicer looking title. <tt>titleize</tt> is meant for creating pretty output.</p>
<h3>Examples</h3>
<pre><code>"man from the boondocks".titleize() # =&gt; "Man From The Boondocks"
"x-men: the last stand".titleize() # =&gt; "X Men: The Last Stand"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">titleize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">titleize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Makes an underscored, lowercase form from the expression in the string.</p>
<h3>Examples</h3>
<pre><code>"ActiveRecord".underscore() # =&gt; "active_record"
</code></pre>
<p>As a rule of thumb you can think of <tt>underscore</tt> as the inverse of <tt>camelize</tt>,
though there are cases where that does not hold:</p>
<pre><code>"SSLError".underscore().camelize() # =&gt; "SslError"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">underscore = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">underscore</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Replaces underscores with dashes in the string.</p>
<h3>Examples</h3>
<pre><code>"puni_puni" # =&gt; "puni-puni"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">dasherize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">dasherize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Replaces special characters in a string so that it may be used as part of a 'pretty' URL.</p>
<h3>Examples</h3>
<pre><code>"Donald E. Knuth".parameterize() # =&gt; "donald-e-knuth"
"Donald E. Knuth".parameterize('_') # =&gt; "donald_e_knuth"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">parameterize = </span><span class="nf">(sep = &#39;-&#39;) -&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">parameterize</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">sep</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Capitalizes the first word and turns underscores into spaces and strips a
trailing "_id", if any. Like <tt>titleize</tt>, this is meant for creating pretty output.</p>
<h3>Examples</h3>
<pre><code>"employee_salary" # =&gt; "Employee salary"
"author_id" # =&gt; "Author"
</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">String</span><span class="o">::</span><span class="nv">humanize = </span><span class="o">-&gt;</span>
<span class="nx">inflect</span><span class="p">.</span><span class="nx">humanize</span><span class="p">(</span><span class="k">this</span><span class="p">)</span>
<span class="nv">exports.enableStringExtensions = </span><span class="nx">enableStringExtensions</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Jump to Line
Something went wrong with that request. Please try again.