UNPKG

@qikdev/sdk

Version:

Promise based Javascript SDK

3,438 lines (935 loc) 61.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>utils - Documentation</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.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav > <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterComparators">activeFilterComparators</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.watchPosition">watchPosition</a></li></ul></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.cleanValue">cleanValue</a></li><li data-type='method'><a href="utils.html#.comma">comma</a></li><li data-type='method'><a href="utils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="utils.html#.exists">exists</a></li><li data-type='method'><a href="utils.html#.extractFromArray">extractFromArray</a></li><li data-type='method'><a href="utils.html#.formatCurrency">formatCurrency</a></li><li data-type='method'><a href="utils.html#.getTypeFromID">getTypeFromID</a></li><li data-type='method'><a href="utils.html#.guid">guid</a></li><li data-type='method'><a href="utils.html#.hash">hash</a></li><li data-type='method'><a href="utils.html#.id">id</a></li><li data-type='method'><a href="utils.html#.ids">ids</a></li><li data-type='method'><a href="utils.html#.isValidEmailAddress">isValidEmailAddress</a></li><li data-type='method'><a href="utils.html#.loadExternalScript">loadExternalScript</a></li><li data-type='method'><a href="utils.html#.loadExternalStyle">loadExternalStyle</a></li><li data-type='method'><a href="utils.html#.machineName">machineName</a></li><li data-type='method'><a href="utils.html#.mapParameters">mapParameters</a></li><li data-type='method'><a href="utils.html#.matchInArray">matchInArray</a></li><li data-type='method'><a href="utils.html#.parseBoolean">parseBoolean</a></li><li data-type='method'><a href="utils.html#.parseDate">parseDate</a></li><li data-type='method'><a href="utils.html#.parseEmail">parseEmail</a></li><li data-type='method'><a href="utils.html#.parseInt">parseInt</a></li><li data-type='method'><a href="utils.html#.parseNumber">parseNumber</a></li><li data-type='method'><a href="utils.html#.parseURL">parseURL</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul> </nav> <div id="main"> <h1 class="page-title">utils</h1> <section> <header> <h2> utils </h2> <div class="class-description usertext">Utility helper functions — id, ids, hashing, parsing, cleaning, and other general-purpose helpers</div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="utils"><span class="type-signature"></span>new utils<span class="signature">()</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line7">line 7</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id=".currencySymbol"><span class="type-signature">(static, constant) </span>currencySymbol<span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1020">line 1020</a> </li></ul></dd> </dl> <div class="description usertext"> A function that will take a currency string and return the symbol </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns £ sdk.utils.currencySymbol('gbp'); //Returns $ sdk.utils.currencySymbol('usd');</code></pre> <h3 class="subsection-title">Methods</h3> <h4 class="name" id=".cleanValue"><span class="type-signature">(static) </span>cleanValue<span class="signature">(data, type, options)</span><span class="type-signature"> &rarr; {*}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line400">line 400</a> </li></ul></dd> </dl> <div class="description usertext"> A helper function for cleaning an input value to match a required type </div> <h5>Example</h5> <pre class="prettyprint"><code>sdk.utils.cleanValue({_id:'1234', title:'Item'...}, 'reference'); // returns '1234' sdk.utils.cleanValue('true', 'boolean'); // returns true sdk.utils.cleanValue('Mr Rogers House', 'key'); // returns 'mrRogersHouse'; sdk.utils.cleanValue('Hello.World@email.COM', 'email'); // returns 'hello.world@email.com';</code></pre> <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">*</span> </td> <td class="description last">The input to clean</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The data type to parse</td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Additional options for parsing</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> the resulting cleaned value </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">*</span> </dd> </dl> <h4 class="name" id=".comma"><span class="type-signature">(static) </span>comma<span class="signature">(array, path)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1228">line 1228</a> </li></ul></dd> </dl> <div class="description usertext"> A helpful class that can take an array of values and return them as a comma seperated string, If the values are objects, then a property to use as the string representation can be specified </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns 'cat, dog, bird' sdk.utils.comma(['cat', 'dog', 'bird']); //Returns 'cat, dog, bird' sdk.utils.comma([{title:'cat'}, {title:'dog'}, {title:'bird'}], 'title');</code></pre> <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>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">The array of values to translate</td> </tr> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">An optional property key to use for each value</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> The resulting comma seperated string </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".errorMessage"><span class="type-signature">(static) </span>errorMessage<span class="signature">(error)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1349">line 1349</a> </li></ul></dd> </dl> <div class="description usertext"> Helper function for retrieving a human readable error message from server error response objects </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>error</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">The error object to translate</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> The resulting human readable error message </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".exists"><span class="type-signature">(static) </span>exists<span class="signature">(value)</span><span class="type-signature"> &rarr; {Boolean}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line123">line 123</a> </li></ul></dd> </dl> <div class="description usertext"> A helper function for checking whether a value is truthy/falsy </div> <h5>Example</h5> <pre class="prettyprint"><code>sdk.utils.exists('undefined'); // false sdk.utils.exists([]); // true sdk.utils.exists(''); // false sdk.utils.exists(undefined); // false</code></pre> <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">Anything</span> </td> <td class="description last">The value to check</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> whether the value is truthy </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Boolean</span> </dd> </dl> <h4 class="name" id=".extractFromArray"><span class="type-signature">(static) </span>extractFromArray<span class="signature">(array, key, sum, flatten, unique, exclude, options)</span><span class="type-signature"> &rarr; {Array}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1096">line 1096</a> </li></ul></dd> </dl> <div class="description usertext"> Returns a subset of values in an array that match a provided rule </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns [12, 45] as all the values sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:45}], 'age'); //Returns 32 sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:20}], 'age', {sum:true});</code></pre> <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>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">The array you want to extract values from</td> </tr> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The path to the child property you want to extract</td> </tr> <tr> <td class="name"><code>sum</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether to sum the extracted values together in total</td> </tr> <tr> <td class="name"><code>flatten</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether to flatten nested child arrays</td> </tr> <tr> <td class="name"><code>unique</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether to only return unique values</td> </tr> <tr> <td class="name"><code>exclude</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether to exclude null or undefined values</td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Pass through extra options for how to extract the values</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> An array of all values retrieved from the array, unless provided arguments require otherwise </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id=".formatCurrency"><span class="type-signature">(static) </span>formatCurrency<span class="signature">(value, currency)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line912">line 912</a> </li></ul></dd> </dl> <div class="description usertext"> A function that will take an integer and a currency string and return a formatted numeric amount rounded to 2 decimal places </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns £10.00 sdk.utils.formatCurrency(1000, 'gbp'); //Returns $10.00 sdk.utils.formatCurrency(1000, 'usd');</code></pre> <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">Integer</span> </td> <td class="description last">The amount in cents</td> </tr> <tr> <td class="name"><code>currency</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The currency to format</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> The formatted value </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".getTypeFromID"><span class="type-signature">(static) </span>getTypeFromID<span class="signature">(id)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line937">line 937</a> </li></ul></dd> </dl> <div class="description usertext"> A function that will take an id and return the type key </div> <h5>Example</h5> <pre class="prettyprint"><code>// Returns 'user' sdk.utils.getTypeFromID('52b523f775beea960013f6cd'); // Returns 'role' sdk.utils.getTypeFromID('62b59cb572fb4772e7b5fa93');</code></pre> <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>id</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The id of an object</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> The key </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".guid"><span class="type-signature">(static) </span>guid<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1382">line 1382</a> </li></ul></dd> </dl> <div class="description usertext"> Generates a globally unique ID, helpful for adding unique keys for iterable loops </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns 4323a78br-z16h-289j-zwl1-938lda334asd sdk.utils.guid()</code></pre> <h5>Returns:</h5> <div class="param-desc"> The new globally unique identifier </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".hash"><span class="type-signature">(static) </span>hash<span class="signature">(array, key)</span><span class="type-signature"> &rarr; {Object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1066">line 1066</a> </li></ul></dd> </dl> <div class="description usertext"> Creates a fast keyed hash object from an array of items </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns { jimbo:{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'} } sdk.utils.hash([{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'}], 'id');</code></pre> <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>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">The array of items to convert into a hash</td> </tr> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The key or path to the property on each item to use as the hashed key</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> A key/value paired object </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id=".id"><span class="type-signature">(static) </span>id<span class="signature">(input, asObjectID)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1269">line 1269</a> </li></ul></dd> </dl> <div class="description usertext"> Returns a specified _id for an object </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns '5cb3d8b3a2219970e6f86927' sdk.utils.id('5cb3d8b3a2219970e6f86927') //Returns true typeof service.id({_id:'5cb3d8b3a2219970e6f86927', title, ...}) == 'string'; //Returns true typeof service.id({_id:'5cb3d8b3a2219970e6f86927'}, true) == 'object';</code></pre> <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>input</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">An object that is or has an _id property</td> </tr> <tr> <td class="name"><code>asObjectID</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether to convert to a Mongo ObjectId</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> Will return either a string or a Mongo ObjectId </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".ids"><span class="type-signature">(static) </span>ids<span class="signature">(array, asObjectID)</span><span class="type-signature"> &rarr; {Array}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1306">line 1306</a> </li></ul></dd> </dl> <div class="description usertext"> Cleans and maps an array of objects to an array of IDs </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns ['5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927'] sdk.utils.ids([{_id:'5cb3d8b3a2219970e6f86927'}, {_id:'5cb3d8b3a2219970e6f86927'}, null, '5cb3d8b3a2219970e6f86927'])</code></pre> <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>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">An array of objects or object ids</td> </tr> <tr> <td class="name"><code>asObjectID</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last">Whether or not to map the ids as Mongo ObjectIds</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> An array of Ids </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id=".isValidEmailAddress"><span class="type-signature">(static) </span>isValidEmailAddress<span class="signature">(emailAddress)</span><span class="type-signature"> &rarr; {Boolean}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line305">line 305</a> </li></ul></dd> </dl> <div class="description usertext"> A helper function for getting a number from some input </div> <h5>Example</h5> <pre class="prettyprint"><code>sdk.utils.isValidEmailAddress('123.com'); // Returns false sdk.utils.isValidEmailAddress('hello@world.com'); // Returns true sdk.utils.isValidEmailAddress('something@special.io'); // Returns true</code></pre> <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>emailAddress</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The email to validate</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> whether or not the input is a valid email address </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Boolean</span> </dd> </dl> <h4 class="name" id=".loadExternalScript"><span class="type-signature">(static) </span>loadExternalScript<span class="signature">(url)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line30">line 30</a> </li></ul></dd> </dl> <div class="description usertext"> A function that dynamically include an external javascript resource ensuring that it will only be included once </div> <h5>Example</h5> <pre class="prettyprint"><code>await sdk.utils.loadExternalScript('https://cdn.javascript.com/external/script.js');</code></pre> <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>url</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The url of the external script</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> A promise that will be resolved once the script has been loaded </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id=".loadExternalStyle"><span class="type-signature">(static) </span>loadExternalStyle<span class="signature">(url)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line76">line 76</a> </li></ul></dd> </dl> <div class="description usertext"> A function that dynamically include an external css resource ensuring that it will only be included once </div> <h5>Example</h5> <pre class="prettyprint"><code>await sdk.utils.loadExternalStyle('https://cdn.css.com/external/style.css');</code></pre> <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>url</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The url of the external css</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> A promise that will be resolved once the css has been loaded </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Promise</span> </dd> </dl> <h4 class="name" id=".machineName"><span class="type-signature">(static) </span>machineName<span class="signature">(string)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1403">line 1403</a> </li></ul></dd> </dl> <div class="description usertext"> Helper function for cleaning strings to use as database ids </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>string</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The string to clean eg. (Awesome Event!)</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> A cleaned and formatted string eg. (awesomeEvent) </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".mapParameters"><span class="type-signature">(static) </span>mapParameters<span class="signature">(parameters)</span><span class="type-signature"> &rarr; {String}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line873">line 873</a> </li></ul></dd> </dl> <div class="description usertext"> A helpful function that can take a keyed object literal and map it to url query string parameters </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns &amp;this=that&amp;hello=world sdk.utils.mapParameters({"this":"that", "hello":"world"})</code></pre> <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>parameters</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">The object you want to transalte</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> The query string </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">String</span> </dd> </dl> <h4 class="name" id=".matchInArray"><span class="type-signature">(static) </span>matchInArray<span class="signature">(array, key, value, comparator)</span><span class="type-signature"> &rarr; {Array}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line1173">line 1173</a> </li></ul></dd> </dl> <div class="description usertext"> A function that can return a selection of values that were found in an array that match a specific rule, This is often used to evaluate expressions within form fields </div> <h5>Example</h5> <pre class="prettyprint"><code>//Returns [{name:'Michael', age:45}] as that is only item in the array that matches the criteria sdk.utils.matchInArray([{name:'Wendy', age:12}, {name:'Michael', age:45}], 'age', 45, '>=');</code></pre> <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>array</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">The array to check</td> </tr> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The javascript dot notation path to extract</td> </tr> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The value to compare against</td> </tr> <tr> <td class="name"><code>comparator</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The logical operator to use to compare the extracted value with the provided value ('>', '<', '>=', '<=', 'in', '==') Defaults to '==' (Is equal to)</td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> Returns an array of matching values </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> <h4 class="name" id=".parseBoolean"><span class="type-signature">(static) </span>parseBoolean<span class="signature">(value)</span><span class="type-signature"> &rarr; {Boolean}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="qik.utils.js.html">qik.utils.js</a>, <a href="qik.utils.js.html#line636">line 636</a> </li></ul></dd> </dl> <div class="description usertext"> A helper function for parsing input as boolean values </div> <h5>Example</h5> <pre class="prettyprint"><code>sdk.utils.parseBoolean('true'); // returns true sdk.utils.parseBoolean('y'); // returns true sdk.utils.parseBoolean('YES'); // returns true sdk.utils.parseBoolean('1'); // returns true sdk.utils.parseBoolean('t'); // returns true sdk.utils.parseBoolean(''); // returns false sdk.utils.parseBoolean('0'); // returns false sdk.uti