forerunnerdb
Version:
A NoSQL document store database for browsers and Node.js.
1,305 lines (341 loc) • 16.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Serialiser</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">Class: Serialiser</h1>
<section>
<header>
<h2>
Serialiser
</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="Serialiser"><span class="type-signature"></span>new Serialiser<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Provides functionality to encode and decode JavaScript objects to strings
and back again. This differs from JSON.stringify and JSON.parse in that
special objects such as dates can be encoded to strings and back again
so that the reconstituted version of the string still contains a JavaScript
date object.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line11">line 11</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_encode"><span class="type-signature">(private) </span>_encode<span class="signature">(data)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Loops the encoders and asks each one if it wants to handle encoding for
the passed data object. If no value is returned (undefined) then the data
will be passed to the next encoder and so on. If a value is returned the
loop will break and the encoded data will 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>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">The data object to handle.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line73">line 73</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The encoded data.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="_parse"><span class="type-signature">(private) </span>_parse<span class="signature">(data, target<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
Handles restoring an object with special data markers back into
it's original format.
</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>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">The object to recurse.</td>
</tr>
<tr>
<td class="name"><code>target</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The target object to restore data to.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line104">line 104</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The final restored object.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="_stringify"><span class="type-signature">(private) </span>_stringify<span class="signature">(data, target<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
Recurse down an object and encode special objects so they can be
stringified and later restored.
</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>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">The object to parse.</td>
</tr>
<tr>
<td class="name"><code>target</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The target object to store converted data to.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line152">line 152</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The converted object.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="parse"><span class="type-signature"></span>parse<span class="signature">(data)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
Converts a previously encoded string back into an object.
</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>data</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The string to convert to an object.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line92">line 92</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The reconstituted object.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="registerDecoder"><span class="type-signature"></span>registerDecoder<span class="signature">(handles, method)</span><span class="type-signature"></span></h4>
<div class="description">
Register a decoder that can handle decoding for a particular
object type.
</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>handles</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the handler e.g. $date. When an object
has a field matching this handler name then this decode will be invoked
to provide a decoded version of the data that was previously encoded by
it's counterpart encoder method.</td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The decoder method.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line60">line 60</a>
</li></ul></dd>
</dl>
<h4 class="name" id="registerEncoder"><span class="type-signature"></span>registerEncoder<span class="signature">(handles, method)</span><span class="type-signature"></span></h4>
<div class="description">
Register an encoder that can handle encoding for a particular
object type.
</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>handles</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the handler e.g. $date.</td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The encoder method.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line37">line 37</a>
</li></ul></dd>
</dl>
<h4 class="name" id="stringify"><span class="type-signature"></span>stringify<span class="signature">(data)</span><span class="type-signature"></span></h4>
<div class="description">
Converts an object to a encoded string representation.
</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>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">The object to encode.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Serialiser.js.html">Serialiser.js</a>, <a href="Serialiser.js.html#line140">line 140</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActiveBucket.html">ActiveBucket</a></li><li><a href="Angular.html">Angular</a></li><li><a href="AutoBind.html">AutoBind</a></li><li><a href="BinaryTree.html">BinaryTree</a></li><li><a href="Collection.html">Collection</a></li><li><a href="CollectionGroup.html">CollectionGroup</a></li><li><a href="Core.html">Core</a></li><li><a href="Db.html">Db</a></li><li><a href="Document.html">Document</a></li><li><a href="Grid.html">Grid</a></li><li><a href="Highchart.html">Highchart</a></li><li><a href="IndexBinaryTree.html">IndexBinaryTree</a></li><li><a href="IndexHashMap.html">IndexHashMap</a></li><li><a href="Infinilist.html">Infinilist</a></li><li><a href="KeyValueStore.html">KeyValueStore</a></li><li><a href="Metrics.html">Metrics</a></li><li><a href="OldView.html">OldView</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Overload.html">Overload</a></li><li><a href="Path.html">Path</a></li><li><a href="Persist.html">Persist</a></li><li><a href="ReactorIO.html">ReactorIO</a></li><li><a href="Serialiser.html">Serialiser</a></li><li><a href="Shared.overload.html">overload</a></li><li><a href="View.html">View</a></li></ul><h3>Mixins</h3><ul><li><a href="ChainReactor.html">ChainReactor</a></li><li><a href="crcTable.html">crcTable</a></li><li><a href="Shared.html">Shared</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%2522boolean,function%2522">"boolean, function"</a></li><li><a href="global.html#%2522string,*,function%2522">"string, *, function"</a></li><li><a href="global.html#%2522string,function%2522">"string, function"</a></li><li><a href="global.html#boolean">boolean</a></li><li><a href="global.html#function">function</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Thu Nov 19 2015 13:31:32 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>