thingsboard/ui/node_modules/messageformat/doc/MessageFormat.formatters.html
2020-05-19 11:43:42 +03:00

740 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: formatters</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: formatters</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="MessageFormat.html">MessageFormat</a>.</span>formatters</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Default number formatting functions in the style of ICU's
<a href="http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html">simpleArg syntax</a>
implemented using the
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl">Intl</a>
object defined by ECMA-402.</p>
<p> <strong>Note</strong>: Intl is not defined in default Node until 0.11.15 / 0.12.0, so
earlier versions require a <a href="https://www.npmjs.com/package/intl">polyfill</a>.
Therefore MessageFormat.intlSupport needs to be true for these default
functions to be available for inclusion in the output.</p></div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line112">line 112</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="MessageFormat.html#setIntlSupport">MessageFormat#setIntlSupport</a></li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".date"><span class="type-signature">(static) </span>date<span class="signature">(value, type<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Represent a date as a short/default/long/full string</p>
<p>The input value needs to be in a form that the
<a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date">Date object</a>
can process using its single-argument form, <code>new Date(value)</code>.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">number</span>
|
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>Either a Unix epoch time in milliseconds, or a string value representing a date</p></td>
</tr>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
'default'
</td>
<td class="description last"><p>One of <code>'short'</code>, <code>'default'</code>, <code>'long'</code> , or <code>full</code></p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line174">line 174</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>var mf = new MessageFormat(['en', 'fi']).setIntlSupport(true);
mf.compile('Today is {T, date}')({ T: Date.now() })
// 'Today is Feb 21, 2016'
mf.compile('Tänään on {T, date}', 'fi')({ T: Date.now() })
// 'Tänään on 21. helmikuuta 2016'
mf.compile('Unix time started on {T, date, full}')({ T: 0 })
// 'Unix time started on Thursday, January 1, 1970'
var cf = mf.compile('{sys} became operational on {d0, date, short}');
cf({ sys: 'HAL 9000', d0: '12 January 1999' })
// 'HAL 9000 became operational on 1/12/1999'</code></pre>
<h4 class="name" id=".number"><span class="type-signature">(static) </span>number<span class="signature">(value, type)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Represent a number as an integer, percent or currency value</p>
<p> Available in MessageFormat strings as <code>{VAR, number, integer|percent|currency}</code>.
Internally, calls Intl.NumberFormat with appropriate parameters. <code>currency</code> will
default to USD; to change, set <code>MessageFormat#currency</code> to the appropriate
three-letter currency code.</p>
</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>value</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>The value to operate on</p></td>
</tr>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>One of <code>'integer'</code>, <code>'percent'</code> , or <code>currency</code></p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line138">line 138</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>var mf = new MessageFormat('en').setIntlSupport(true);
mf.currency = 'EUR'; // needs to be set before first compile() call
mf.compile('{N} is almost {N, number, integer}')({ N: 3.14 })
// '3.14 is almost 3'
mf.compile('{P, number, percent} complete')({ P: 0.99 })
// '99% complete'
mf.compile('The total is {V, number, currency}.')({ V: 5.5 })
// 'The total is €5.50.'</code></pre>
<h4 class="name" id=".time"><span class="type-signature">(static) </span>time<span class="signature">(value, type<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Represent a time as a short/default/long string</p>
<p>The input value needs to be in a form that the
<a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date">Date object</a>
can process using its single-argument form, <code>new Date(value)</code>.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">number</span>
|
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>Either a Unix epoch time in milliseconds, or a string value representing a date</p></td>
</tr>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
'default'
</td>
<td class="description last"><p>One of <code>'short'</code>, <code>'default'</code>, <code>'long'</code> , or <code>full</code></p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line207">line 207</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>var mf = new MessageFormat(['en', 'fi']).setIntlSupport(true);
mf.compile('The time is now {T, time}')({ T: Date.now() })
// 'The time is now 11:26:35 PM'
mf.compile('Kello on nyt {T, time}', 'fi')({ T: Date.now() })
// 'Kello on nyt 23.26.35'
var cf = mf.compile('The Eagle landed at {T, time, full} on {T, date, full}');
cf({ T: '1969-07-20 20:17:40 UTC' })
// 'The Eagle landed at 10:17:40 PM GMT+2 on Sunday, July 20, 1969'</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Compiler.html">Compiler</a></li><li><a href="MessageFormat.html">MessageFormat</a></li><li><a href="Runtime.html">Runtime</a></li></ul><h3>Namespaces</h3><ul><li><a href="MessageFormat.formatters.html">formatters</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Sep 27 2016 00:30:24 GMT+0300 (EEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>