mcode-data
Version:
Our Data Handling functions. These support type checking and type coercion and conversion of Objects--ints, string, number, JSON, any--to commonize data handling and type checking.
644 lines (169 loc) • 9.22 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: mcode</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: mcode</h1>
<section>
<header>
<h2>mcode</h2>
</header>
<article>
<div class="container-overview">
<div class="description">mcode namespace containing functions and constants.</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#line95">line 95</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".call"><span class="type-signature">(static) </span>call<span class="signature">(key, keys, values)</span><span class="type-signature"> → {any}</span></h4>
<div class="description">
Calls a function from a 'destination' list using a 'key' index found in a 'source' list.
</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>key</code></td>
<td class="type">
<span class="param-type">any</span>
</td>
<td class="description last">a JavaScript value viewed as a 'key' in the 'source' list.</td>
</tr>
<tr>
<td class="name"><code>keys</code></td>
<td class="type">
<span class="param-type">Array.<any></span>
</td>
<td class="description last">a JavaScript array of values viewed as 'keys' in the 'source' list.</td>
</tr>
<tr>
<td class="name"><code>values</code></td>
<td class="type">
<span class="param-type">Array.<any></span>
</td>
<td class="description last">a JavaScript array of values viewed as 'values' in the 'destination' list.</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#line209">line 209</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the value from the function in 'destination' list corresponding to the 'key' in the 'source' list.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">any</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>let keys = [1, 2, 3, 4, 5, null];
let values = [function1, function2, function3, function4, function5, default];
let key = 3;
let value = mcode.swap(key, keys, values); // value = (return value of function3)</code></pre>
<h4 class="name" id=".ready"><span class="type-signature">(static) </span>ready<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Logs a message to the Console when the module is loaded to show version.
</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#line101">line 101</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".swap"><span class="type-signature">(static) </span>swap<span class="signature">(key, keys, values)</span><span class="type-signature"> → {any}</span></h4>
<div class="description">
Swaps a 'key' from a 'source' list with a 'value' in a 'destination' list.
</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>key</code></td>
<td class="type">
<span class="param-type">any</span>
</td>
<td class="description last">a JavaScript value viewed as a 'key' in the 'source' list.</td>
</tr>
<tr>
<td class="name"><code>keys</code></td>
<td class="type">
<span class="param-type">Array.<any></span>
</td>
<td class="description last">a JavaScript array of values viewed as 'keys' in the 'source' list.</td>
</tr>
<tr>
<td class="name"><code>values</code></td>
<td class="type">
<span class="param-type">Array.<any></span>
</td>
<td class="description last">a JavaScript array of values viewed as 'values' in the 'destination' list.</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#line111">line 111</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the value from the 'destination' list corresponding to the 'key' in the 'source' list.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">any</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>let list1 = [1, 2, 3, 4, 5, 0];
let list2 = ['one', 'two', 'three', 'four', 'five', 'default'];
let list3 = [false, true, false, true, false, false];
let list4 = [{ key: 1, property: ONE },
{ key: 2, property: TWO },
{ key: 3, property: THREE },
{ key: 4, property: FOUR },
{ key: 5, property: FIVE },
{ key: 0, property: DEFAULT }];
let key = null;
let value = null;
1) straight swap of two values...
key = 3;
value = mcode.swap(key, list1, list2); // value = 'three'
key = 6;
value = mcode.swap(key, list1, list2); // value = 'default'
key = 0;
value = mcode.swap(key, list1, list2); // value = 'default'
2) the same lists can be used the other way around...
key = 'three';
value = mcode.swap(key, list2, list1); // value = 3
key = 'six';
value = mcode.swap(key, list2, list1); // value = 0
3) any two lists on the same subject (i.e.: the same length) can be used...
key = 3;
value = mcode.swap(key, list1, list3); // value = false
key = 'three';
value = mcode.swap(key, list2, list4); // value = { key: 4, property: FOUR }
...seems simple enough, but keep in mind that the 'key' and 'value' in the lists can be any JavaScript value, including:
- a number
- a string
- a boolean
- an object
- a function
- a class
- a module
- a BigInt
- a Promise
- an Array
- a JSON object
- null
- undefined
etc.</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="mcode.html">mcode</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Wed Jan 31 2024 12:39:37 GMT-0500 (Eastern Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>