UNPKG

numbr

Version:

A fast number formatting library, based on Numeral.js

1,275 lines (386 loc) 16.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Namespace: numbr</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Namespace: numbr</h1> <section> <header> <h2> numbr </h2> </header> <article> <div class="container-overview"> <div class="description">Function wrapper for creating new Numbr instances, it also has useful static methods to control the global module behaviour.</div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line263">line 263</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Classes</h3> <dl> <dt><a href="numbr.CompiledFormat.html">CompiledFormat</a></dt> <dd></dd> <dt><a href="numbr.Consumer.html">Consumer</a></dt> <dd></dd> <dt><a href="numbr.Numbr.html">Numbr</a></dt> <dd></dd> <dt><a href="numbr.Step.html">Step</a></dt> <dd></dd> </dl> <h3 class="subsection-title">Members</h3> <dl> <dt> <h4 class="name" id="echoConsumer"><span class="type-signature">(static) </span>echoConsumer<span class="type-signature"> :Consumer</span></h4> </dt> <dd> <div class="description"> A simple consumer that echoes back as many characters as possible in one step. This is the default consumer. </div> <h5>Type:</h5> <ul> <li> <span class="param-type">Consumer</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line391">line 391</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="noopConsumer"><span class="type-signature">(static) </span>noopConsumer<span class="type-signature"> :Consumer</span></h4> </dt> <dd> <div class="description"> A simple consumer that consumes the single character is given and does nothing else. You can set this consumer as the default by using <a href="numbr.html#setDefaultConsumer">numbr.setDefaultConsumer</a> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">Consumer</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line416">line 416</a> </li></ul></dd> </dl> </dd> </dl> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="addConsumer"><span class="type-signature">(static) </span>addConsumer<span class="signature">(consumer)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Adds a consumer to the list of global consumers. Consumers are used to translate the string format input into actual transforming steps. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>consumer</code></td> <td class="type"> <span class="param-type">Consumer</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line376">line 376</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="cacheEnabled"><span class="type-signature">(static) </span>cacheEnabled<span class="signature">(enabled)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Enables or disables the format cache. By default every format is compiled into a series of transformation functions that are cached and reused every time Numbr.format is called. Disabling the cache may cause a significant performance hit and it is not recommended. Most applications will probably use just a handful of formats, so the memory overhead is non-existent. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>enabled</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Whether to enable or disable the cache</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line356">line 356</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="compile"><span class="type-signature">(static) </span>compile<span class="signature">(fmt)</span><span class="type-signature"> &rarr; {CompiledFormat}</span></h4> </dt> <dd> <div class="description"> Compiles the given string into a CompiledFormat object ready to be used. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fmt</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line281">line 281</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">CompiledFormat</span> </dd> </dl> </dd> <dt> <h4 class="name" id="defaultFormat"><span class="type-signature">(static) </span>defaultFormat<span class="signature">(fmt)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Sets the default format. The default format is used if Numbr#format is called without arguments. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fmt</code></td> <td class="type"> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line299">line 299</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="language"><span class="type-signature">(static) </span>language<span class="signature">(langCode<span class="signature-attributes">opt</span>, langDef<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Gets the global language, sets the global language or loads a language. If called with no arguments, returns the global language. If called with just the language code, it sets the global language. If called with both arguments, the language is just loaded. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>langCode</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The language code</td> </tr> <tr> <td class="name"><code>langDef</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">A valid language definition</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line334">line 334</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="setDefaultConsumer"><span class="type-signature">(static) </span>setDefaultConsumer<span class="signature">(consumer)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Sets the default consumer. The default consumer is used when no other consumer is able to consume a slice of the input format string. By default, this is <a href="numbr.html#echoConsumer">numbr.echoConsumer</a>. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>consumer</code></td> <td class="type"> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line366">line 366</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="setGlobalLang"><span class="type-signature">(static) </span>setGlobalLang<span class="signature">(langCode)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Sets the global language. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>langCode</code></td> <td class="type"> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line315">line 315</a> </li></ul></dd> </dl> </dd> <dt> <h4 class="name" id="zeroFormat"><span class="type-signature">(static) </span>zeroFormat<span class="signature">(fmt)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Sets the global zero format. If defined, the zero format is used as the outout of Numbr#format whenever the wrapped value === 0. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fmt</code></td> <td class="type"> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="numbr.js.html">numbr.js</a>, <a href="numbr.js.html#line290">line 290</a> </li></ul></dd> </dl> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="numbr.CompiledFormat.html">CompiledFormat</a></li><li><a href="numbr.Consumer.html">Consumer</a></li><li><a href="numbr.Numbr.html">Numbr</a></li><li><a href="numbr.Step.html">Step</a></li></ul><h3>Namespaces</h3><ul><li><a href="numbr.html">numbr</a></li></ul> </nav> <br clear="both"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 30 2014 02:08:18 GMT-0500 (Central Daylight Time (Mexico)) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>