@qikdev/sdk 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/access.html +16371 -0
- package/dist/api.html +1503 -0
- package/dist/auth.html +8455 -0
- package/dist/cache.html +1135 -0
- package/dist/content.html +10067 -0
- package/dist/files.html +3415 -0
- package/dist/filter.html +4973 -0
- package/dist/geo.html +3851 -0
- package/dist/global.html +328 -0
- package/dist/index.html +96 -0
- package/dist/main.js +2 -3
- package/dist/module-QikStorage-CookieStorageAdapter.html +1177 -0
- package/dist/module-QikStorage-LocalStorageAdapter.html +329 -0
- package/dist/module-QikStorage-StorageAdapter.html +3457 -0
- package/dist/module-QikStorage.html +1445 -0
- package/dist/qik.access.js.html +904 -0
- package/dist/qik.api.js.html +409 -0
- package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
- package/dist/qik.cache.js.html +125 -0
- package/dist/qik.content.js.html +967 -0
- package/dist/qik.core.js.html +322 -0
- package/dist/qik.files.js.html +249 -0
- package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +2 -2
- package/dist/qik.geo.js.html +963 -0
- package/dist/qik.socket.js.html +451 -0
- package/dist/qik.storage.js.html +375 -0
- package/dist/qik.system.js.html +117 -0
- package/dist/qik.utils.js.html +1542 -0
- package/dist/socket.html +2975 -0
- package/dist/{docs/styles → styles}/jsdoc.css +2 -2
- package/dist/system.html +523 -0
- package/package.json +2 -2
- package/src/api/qik.socket.js +18 -12
- package/src/version.js +1 -1
- package/dist/docs/access.html +0 -3826
- package/dist/docs/api.html +0 -1356
- package/dist/docs/auth.html +0 -2180
- package/dist/docs/cache.html +0 -351
- package/dist/docs/content.html +0 -2560
- package/dist/docs/files.html +0 -779
- package/dist/docs/filter.html +0 -1355
- package/dist/docs/index.html +0 -96
- package/dist/docs/qik.access.js.html +0 -790
- package/dist/docs/qik.api.js.html +0 -511
- package/dist/docs/qik.cache.js.html +0 -131
- package/dist/docs/qik.content.js.html +0 -918
- package/dist/docs/qik.core.js.html +0 -301
- package/dist/docs/qik.files.js.html +0 -219
- package/dist/docs/qik.socket.js.html +0 -416
- package/dist/docs/qik.system.js.html +0 -117
- package/dist/docs/qik.utils.js.html +0 -1467
- package/dist/docs/socket.html +0 -810
- package/dist/docs/system.html +0 -197
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
- /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
- /package/dist/{docs/scripts → scripts}/nav.js +0 -0
- /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
- /package/dist/{docs/scripts → scripts}/search.js +0 -0
- /package/dist/{docs/styles → styles}/prettify.css +0 -0
|
@@ -1,1467 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<title>qik.utils.js - Documentation</title>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
-
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
-
<!--[if lt IE 9]>
|
|
12
|
-
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
-
<![endif]-->
|
|
14
|
-
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
-
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
-
<script src="scripts/nav.js" defer></script>
|
|
17
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
|
|
21
|
-
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
-
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
-
<div class="navicon"></div>
|
|
24
|
-
</label>
|
|
25
|
-
|
|
26
|
-
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
-
|
|
28
|
-
<nav >
|
|
29
|
-
|
|
30
|
-
<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#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</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#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.patch">patch</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</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#.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#.activeFilterKeys">activeFilterKeys</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="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></ul>
|
|
31
|
-
</nav>
|
|
32
|
-
|
|
33
|
-
<div id="main">
|
|
34
|
-
|
|
35
|
-
<h1 class="page-title">qik.utils.js</h1>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<section>
|
|
44
|
-
<article>
|
|
45
|
-
<pre class="prettyprint source linenums"><code>import _get from 'lodash/get.js';
|
|
46
|
-
import _isDate from 'lodash/isDate.js';
|
|
47
|
-
import _startsWith from 'lodash/startsWith.js';
|
|
48
|
-
import _isObject from 'lodash/isObject.js';
|
|
49
|
-
import _camelCase from 'lodash/camelCase.js';
|
|
50
|
-
import axios from 'axios';
|
|
51
|
-
import { isBrowser, isNode } from 'browser-or-node';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
56
|
-
|
|
57
|
-
const service = {};
|
|
58
|
-
|
|
59
|
-
////////////////////////////////////
|
|
60
|
-
|
|
61
|
-
const loadedExternalScripts = {}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A function that dynamically include an external javascript resource
|
|
66
|
-
* ensuring that it will only be included once
|
|
67
|
-
* @alias utils.loadExternalScript
|
|
68
|
-
* @param {String} url The url of the external script
|
|
69
|
-
* @return {Promise} A promise that will be resolved once the script has been loaded
|
|
70
|
-
* @example
|
|
71
|
-
*
|
|
72
|
-
* await sdk.utils.loadExternalScript('https://cdn.javascript.com/external/script.js');
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
service.loadExternalScript = function(url) {
|
|
76
|
-
|
|
77
|
-
const promise = new Promise(createNewScript);
|
|
78
|
-
|
|
79
|
-
function createNewScript(resolve, reject) {
|
|
80
|
-
|
|
81
|
-
if (!document) {
|
|
82
|
-
return reject('document is undefined')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (loadedExternalScripts[url]) {
|
|
86
|
-
return resolve(url);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Avoid duplicate scripts
|
|
90
|
-
loadedExternalScripts[url] = true;
|
|
91
|
-
|
|
92
|
-
//////////////////////////////////////
|
|
93
|
-
|
|
94
|
-
var script = document.createElement('script');
|
|
95
|
-
script.type = 'text/javascript';
|
|
96
|
-
script.async = true;
|
|
97
|
-
script.onload = function() {
|
|
98
|
-
console.log('Loaded external script', url);
|
|
99
|
-
return resolve(url);
|
|
100
|
-
};
|
|
101
|
-
script.src = url;
|
|
102
|
-
|
|
103
|
-
// Inject it into the document's <head> tag
|
|
104
|
-
document.head.appendChild(script);
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return promise;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const loadedExternalStyles = {}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* A function that dynamically include an external css resource
|
|
117
|
-
* ensuring that it will only be included once
|
|
118
|
-
* @alias utils.loadExternalStyle
|
|
119
|
-
* @param {String} url The url of the external css
|
|
120
|
-
* @return {Promise} A promise that will be resolved once the css has been loaded
|
|
121
|
-
* @example
|
|
122
|
-
*
|
|
123
|
-
* await sdk.utils.loadExternalStyle('https://cdn.css.com/external/style.css');
|
|
124
|
-
*/
|
|
125
|
-
service.loadExternalStyle = function(url) {
|
|
126
|
-
|
|
127
|
-
const promise = new Promise(createNewScript);
|
|
128
|
-
|
|
129
|
-
function createNewScript(resolve, reject) {
|
|
130
|
-
|
|
131
|
-
if (!document) {
|
|
132
|
-
return reject('document is undefined')
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (loadedExternalStyles[url]) {
|
|
136
|
-
return resolve(url);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Avoid duplicate scripts
|
|
140
|
-
loadedExternalStyles[url] = true;
|
|
141
|
-
|
|
142
|
-
//////////////////////////////////////
|
|
143
|
-
|
|
144
|
-
var script = document.createElement('link');
|
|
145
|
-
script.setAttribute('rel', 'stylesheet')
|
|
146
|
-
script.setAttribute('type', 'text/css')
|
|
147
|
-
script.setAttribute('href', url)
|
|
148
|
-
script.onload = function() {
|
|
149
|
-
console.log('Loaded external stylesheet', url);
|
|
150
|
-
return resolve(url);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// Inject it into the document's <head> tag
|
|
154
|
-
document.head.appendChild(script);
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return promise;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
163
|
-
|
|
164
|
-
service.exists = function(value) {
|
|
165
|
-
var isUndefinedOrNull;
|
|
166
|
-
|
|
167
|
-
////////////////////////
|
|
168
|
-
|
|
169
|
-
if (Array.isArray(value)) {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
////////////////////////
|
|
174
|
-
|
|
175
|
-
if (value === 0) {
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
////////////////////////
|
|
180
|
-
|
|
181
|
-
switch (typeof value) {
|
|
182
|
-
case 'undefined':
|
|
183
|
-
case 'null':
|
|
184
|
-
isUndefinedOrNull = true;
|
|
185
|
-
break;
|
|
186
|
-
default:
|
|
187
|
-
var string = String(value).toLowerCase();
|
|
188
|
-
switch (string) {
|
|
189
|
-
case '':
|
|
190
|
-
case 'undefined':
|
|
191
|
-
case 'null':
|
|
192
|
-
isUndefinedOrNull = true;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return !!!isUndefinedOrNull;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
//////////////////////////////////
|
|
202
|
-
|
|
203
|
-
service.parseDate = function(input) {
|
|
204
|
-
|
|
205
|
-
if (!input) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (_isDate(input)) {
|
|
210
|
-
return input;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
//Attempt to create a date
|
|
214
|
-
var d = new Date(input);
|
|
215
|
-
var isValid = d instanceof Date && !isNaN(d);
|
|
216
|
-
|
|
217
|
-
if (isValid) {
|
|
218
|
-
return d;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
service.parseURL = function(string) {
|
|
225
|
-
|
|
226
|
-
if (!string) {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const relative = _startsWith(string, '/');
|
|
231
|
-
if (relative) {
|
|
232
|
-
return string;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (_startsWith(string, '://')) {
|
|
236
|
-
return string;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (_startsWith(string, 'mailto:')) {
|
|
240
|
-
return string;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (_startsWith(string, 'tel:')) {
|
|
244
|
-
return string;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (_startsWith(string, 'sms:')) {
|
|
248
|
-
return string;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
//////////////////////////////////
|
|
252
|
-
//If someone entered an email by accident
|
|
253
|
-
var email = service.parseEmail(string);
|
|
254
|
-
//Convert it to a mailto link
|
|
255
|
-
if (email && email === string) {
|
|
256
|
-
return `mailto:${email}`
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
//////////////////////////////////
|
|
260
|
-
|
|
261
|
-
const withHttp = string => !/^https?:\/\//i.test(string) ? `http://${string}` : string;
|
|
262
|
-
string = withHttp(string);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var valid = RegExp('(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+@]*)*(\\?[;&a-z\\d%_.~+=-@]*)?(\\#[-a-z\\d_@]*)?$', 'i').test(string);
|
|
267
|
-
|
|
268
|
-
if (!valid) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
///////////////////////////
|
|
275
|
-
|
|
276
|
-
return withHttp(string)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
///////////////////////////////////////////////
|
|
281
|
-
|
|
282
|
-
service.parseNumber = function(input, decimalPoints) {
|
|
283
|
-
if (!input) {
|
|
284
|
-
return 0;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
input = Number(input);
|
|
288
|
-
if (isNaN(input)) {
|
|
289
|
-
return 0;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (decimalPoints) {
|
|
293
|
-
var str = input.toFixed(decimalPoints);
|
|
294
|
-
input = service.parseNumber(str);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return input;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
service.isValidEmailAddress = function(email) {
|
|
302
|
-
|
|
303
|
-
var tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
|
|
304
|
-
|
|
305
|
-
if (!email) return false;
|
|
306
|
-
|
|
307
|
-
var emailParts = email.split('@');
|
|
308
|
-
|
|
309
|
-
if (emailParts.length !== 2) return false
|
|
310
|
-
|
|
311
|
-
var account = emailParts[0];
|
|
312
|
-
var address = emailParts[1];
|
|
313
|
-
|
|
314
|
-
if (account.length > 64) return false
|
|
315
|
-
|
|
316
|
-
else if (address.length > 255) return false
|
|
317
|
-
|
|
318
|
-
var domainParts = address.split('.');
|
|
319
|
-
if (domainParts.some(function(part) {
|
|
320
|
-
return part.length > 63;
|
|
321
|
-
})) return false;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (!tester.test(email)) return false;
|
|
325
|
-
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
service.parseEmail = function(input) {
|
|
331
|
-
|
|
332
|
-
if (!input) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
var lowercase = String(input).toLowerCase();
|
|
337
|
-
var valid = service.isValidEmailAddress(lowercase);
|
|
338
|
-
|
|
339
|
-
if (!valid) {
|
|
340
|
-
return false;
|
|
341
|
-
} else {
|
|
342
|
-
return lowercase;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
//////////////////////////////////
|
|
347
|
-
|
|
348
|
-
service.parseInt = function(input) {
|
|
349
|
-
if (!input) {
|
|
350
|
-
return 0;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
input = parseInt(input);
|
|
354
|
-
if (isNaN(input)) {
|
|
355
|
-
return 0;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return input;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
service.cleanValue = function(data, type, options) {
|
|
364
|
-
|
|
365
|
-
if (!options) {
|
|
366
|
-
options = {};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
////////////////////////
|
|
370
|
-
|
|
371
|
-
var noInputValue = service.exists(data);
|
|
372
|
-
if (options.strict && noInputValue && type != 'boolean') {
|
|
373
|
-
return data;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
////////////////////////
|
|
377
|
-
|
|
378
|
-
switch (type) {
|
|
379
|
-
case 'reference':
|
|
380
|
-
return service.id(data, true);
|
|
381
|
-
break;
|
|
382
|
-
case 'boolean':
|
|
383
|
-
return service.parseBoolean(data);
|
|
384
|
-
break;
|
|
385
|
-
case 'url':
|
|
386
|
-
return service.parseURL(data);
|
|
387
|
-
break;
|
|
388
|
-
case 'key':
|
|
389
|
-
return service.machineName(data);
|
|
390
|
-
break;
|
|
391
|
-
case 'email':
|
|
392
|
-
return service.parseEmail(data);
|
|
393
|
-
break;
|
|
394
|
-
case 'date':
|
|
395
|
-
var parsed = service.parseDate(data, options);
|
|
396
|
-
|
|
397
|
-
if (parsed === undefined) {
|
|
398
|
-
return;
|
|
399
|
-
} else {
|
|
400
|
-
return parsed;
|
|
401
|
-
}
|
|
402
|
-
break;
|
|
403
|
-
case 'number':
|
|
404
|
-
case 'decimal':
|
|
405
|
-
case 'float':
|
|
406
|
-
var val = service.parseNumber(data);
|
|
407
|
-
if (String(val) == String(Number(data))) {
|
|
408
|
-
return val;
|
|
409
|
-
}
|
|
410
|
-
return;
|
|
411
|
-
break;
|
|
412
|
-
case 'integer':
|
|
413
|
-
var val = service.parseInt(data);
|
|
414
|
-
if (String(val) == String(parseInt(data))) {
|
|
415
|
-
return val;
|
|
416
|
-
}
|
|
417
|
-
return;
|
|
418
|
-
break;
|
|
419
|
-
case 'group':
|
|
420
|
-
return data;
|
|
421
|
-
break;
|
|
422
|
-
case 'object':
|
|
423
|
-
if (_isObject(data) && !Array.isArray(data)) {
|
|
424
|
-
return data
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return;
|
|
428
|
-
break;
|
|
429
|
-
case 'string':
|
|
430
|
-
if (service.exists(data)) {
|
|
431
|
-
var stringed = String(data);
|
|
432
|
-
if (stringed == '[object Object]') {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return stringed
|
|
437
|
-
} else {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// if(!data) {
|
|
442
|
-
// return '';
|
|
443
|
-
// }
|
|
444
|
-
|
|
445
|
-
// if(Array.isArray(data)) {
|
|
446
|
-
// return JSON.stringify(data);
|
|
447
|
-
// }
|
|
448
|
-
|
|
449
|
-
// if(Object.isObject(data)) {
|
|
450
|
-
// return JSON.stringify(data);
|
|
451
|
-
// }
|
|
452
|
-
|
|
453
|
-
// return String(data);
|
|
454
|
-
|
|
455
|
-
// break;
|
|
456
|
-
default:
|
|
457
|
-
return String(data)
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
service.isValidValue = function(value, dataType, strict) {
|
|
465
|
-
|
|
466
|
-
var isValue = service.exists(value);
|
|
467
|
-
var valueIsNumber = (typeof value == 'number')
|
|
468
|
-
|
|
469
|
-
////////////////////////
|
|
470
|
-
|
|
471
|
-
var isValidEntry = false;
|
|
472
|
-
|
|
473
|
-
if (!isValue) {
|
|
474
|
-
return false;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
////////////////////////
|
|
478
|
-
|
|
479
|
-
switch (dataType) {
|
|
480
|
-
|
|
481
|
-
case 'url':
|
|
482
|
-
if (strict) {
|
|
483
|
-
isValidEntry = _startsWith(value, '/') || _startsWith(value, '://') || _startsWith(value, 'http://') || _startsWith(value, 'https://');
|
|
484
|
-
} else {
|
|
485
|
-
isValidEntry = String(value) === service.parseURL(value);
|
|
486
|
-
}
|
|
487
|
-
break;
|
|
488
|
-
case 'key':
|
|
489
|
-
isValidEntry = String(value) === service.machineName(value);
|
|
490
|
-
break;
|
|
491
|
-
case 'date':
|
|
492
|
-
|
|
493
|
-
//If we are being strict
|
|
494
|
-
if (strict) {
|
|
495
|
-
//And the input is not a javascript date object
|
|
496
|
-
if (typeof value != 'object' || !_isDate(value)) {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
///////////////////////////////
|
|
502
|
-
var parsed = service.parseDate(value);
|
|
503
|
-
return parsed !== undefined;
|
|
504
|
-
break;
|
|
505
|
-
case 'email':
|
|
506
|
-
|
|
507
|
-
if (strict) {
|
|
508
|
-
isValidEntry = value === service.parseEmail(value);
|
|
509
|
-
} else {
|
|
510
|
-
isValidEntry = String(value).toLowerCase() === service.parseEmail(value);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
break;
|
|
514
|
-
case 'number':
|
|
515
|
-
case 'decimal':
|
|
516
|
-
case 'float':
|
|
517
|
-
if (strict) {
|
|
518
|
-
isValidEntry = valueIsNumber && (Number(value) === service.parseNumber(value));
|
|
519
|
-
} else {
|
|
520
|
-
isValidEntry = Number(value) === service.parseNumber(value);
|
|
521
|
-
}
|
|
522
|
-
break;
|
|
523
|
-
case 'integer':
|
|
524
|
-
if (strict) {
|
|
525
|
-
isValidEntry = valueIsNumber && (Number(value) === service.parseInt(value));
|
|
526
|
-
} else {
|
|
527
|
-
isValidEntry = Number(value) === service.parseInt(value);
|
|
528
|
-
}
|
|
529
|
-
break;
|
|
530
|
-
case 'boolean':
|
|
531
|
-
|
|
532
|
-
var parsed = service.parseBoolean(value);
|
|
533
|
-
|
|
534
|
-
//Only accept true booleans
|
|
535
|
-
if (strict) {
|
|
536
|
-
if (value === true || value === false) {
|
|
537
|
-
isValidEntry = value === parsed;
|
|
538
|
-
}
|
|
539
|
-
} else {
|
|
540
|
-
isValidEntry = parsed === true || parsed === false;
|
|
541
|
-
}
|
|
542
|
-
break;
|
|
543
|
-
case 'reference':
|
|
544
|
-
if (strict) {
|
|
545
|
-
isValidEntry = String(value) === service.id(value);
|
|
546
|
-
} else {
|
|
547
|
-
isValidEntry = !!service.id(value);
|
|
548
|
-
}
|
|
549
|
-
break;
|
|
550
|
-
case 'string':
|
|
551
|
-
var checkString = String(value);
|
|
552
|
-
if (strict) {
|
|
553
|
-
if (typeof value != 'string') {
|
|
554
|
-
return false;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (checkString == '[object Object]') {
|
|
559
|
-
return false;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
isValidEntry = true;
|
|
563
|
-
break;
|
|
564
|
-
// case 'group':
|
|
565
|
-
// isValidEntry = _isObject(value);
|
|
566
|
-
// break;
|
|
567
|
-
case 'object':
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
isValidEntry = _isObject(value) && !Array.isArray(value);
|
|
571
|
-
break;
|
|
572
|
-
case 'array':
|
|
573
|
-
isValidEntry = Array.isArray(value);
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
////////////////////////
|
|
578
|
-
|
|
579
|
-
return isValidEntry
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
service.parseBoolean = function(value) {
|
|
583
|
-
switch (String(value).toLowerCase()) {
|
|
584
|
-
case 'true':
|
|
585
|
-
case 'y':
|
|
586
|
-
case 'yes':
|
|
587
|
-
case '1':
|
|
588
|
-
case 't':
|
|
589
|
-
value = true;
|
|
590
|
-
break;
|
|
591
|
-
case 'false':
|
|
592
|
-
case 'n':
|
|
593
|
-
case 'no':
|
|
594
|
-
case '0':
|
|
595
|
-
case 'f':
|
|
596
|
-
case 'undefined':
|
|
597
|
-
case 'null':
|
|
598
|
-
case '':
|
|
599
|
-
case '-1':
|
|
600
|
-
value = false;
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return !!value;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
611
|
-
|
|
612
|
-
service.clone = function(input) {
|
|
613
|
-
return JSON.parse(JSON.stringify(input));
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
617
|
-
|
|
618
|
-
service.mapFields = function(fields, options) {
|
|
619
|
-
|
|
620
|
-
if (!options) {
|
|
621
|
-
options = {};
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
//////////////////////////////
|
|
625
|
-
|
|
626
|
-
var output = [];
|
|
627
|
-
var trail = [];
|
|
628
|
-
var titles = [];
|
|
629
|
-
var currentDepth = 1;
|
|
630
|
-
var depthLimit = options.depth;
|
|
631
|
-
var delimiter = options.arrayDelimeter || '[]';
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
//Loop through each field
|
|
635
|
-
fields.forEach(mapField);
|
|
636
|
-
|
|
637
|
-
//////////////////////////////
|
|
638
|
-
|
|
639
|
-
//Recursively map the fields
|
|
640
|
-
function mapField(field, i) {
|
|
641
|
-
var fieldKey = field.key;
|
|
642
|
-
var isGroup = field.type == 'group';
|
|
643
|
-
var singleValue = (field.minimum === field.maximum) && field.minimum === 1;
|
|
644
|
-
var asObject = field.asObject; // || (isGroup && singleValue);
|
|
645
|
-
var isLayout = isGroup && !asObject;
|
|
646
|
-
|
|
647
|
-
//////////////////////////////////
|
|
648
|
-
|
|
649
|
-
// Whether to clone the field or use the existing reference
|
|
650
|
-
var mapped = options.original ? field : service.clone(field);
|
|
651
|
-
|
|
652
|
-
mapped.trail = trail.slice();
|
|
653
|
-
mapped.trail.push(fieldKey)
|
|
654
|
-
|
|
655
|
-
mapped.path = mapped.trail.join('.');
|
|
656
|
-
mapped.titles = titles.slice();
|
|
657
|
-
mapped.titles.push(field.title || '')
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
const isNotLayoutOrIsAllowed = (!isLayout || options.includeLayout);
|
|
661
|
-
|
|
662
|
-
//If its an actual element or we've asked to include
|
|
663
|
-
//layout only elements
|
|
664
|
-
if (isNotLayoutOrIsAllowed) {
|
|
665
|
-
//Add it to the mix
|
|
666
|
-
output.push(mapped);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
//////////////////////////////////
|
|
670
|
-
|
|
671
|
-
//Now see if there are child fields and should we go further
|
|
672
|
-
var limitHit = depthLimit && (currentDepth >= depthLimit);
|
|
673
|
-
|
|
674
|
-
//If there are child fields for this field
|
|
675
|
-
if (field.fields && field.fields.length) {
|
|
676
|
-
//If it's just a group with no extra key
|
|
677
|
-
if (isLayout) {
|
|
678
|
-
//Loop through fields as if they are at the same depth
|
|
679
|
-
field.fields.forEach(mapField)
|
|
680
|
-
} else {
|
|
681
|
-
|
|
682
|
-
//We don't need to traverse any further
|
|
683
|
-
//because we hit the limit
|
|
684
|
-
if (limitHit) {
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
//Move down a level and add to the object
|
|
689
|
-
//Include the key in the path trail
|
|
690
|
-
currentDepth++;
|
|
691
|
-
|
|
692
|
-
let injectKey = fieldKey;
|
|
693
|
-
if (options.includeArrayDelimeter) {
|
|
694
|
-
if (!singleValue) {
|
|
695
|
-
injectKey = `${fieldKey}${delimiter}`
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
trail.push(injectKey)
|
|
699
|
-
titles.push(field.title);
|
|
700
|
-
|
|
701
|
-
//Loop through each field
|
|
702
|
-
field.fields.forEach(mapField)
|
|
703
|
-
|
|
704
|
-
//Move back up a level before we go to the next field
|
|
705
|
-
currentDepth--;
|
|
706
|
-
trail.pop();
|
|
707
|
-
titles.pop();
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
return output;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* A helpful function that can take a keyed object literal and map it to url query string parameters
|
|
721
|
-
* @alias utils.mapParameters
|
|
722
|
-
* @param {Object} parameters The object you want to transalte
|
|
723
|
-
* @return {String} The query string
|
|
724
|
-
* @example
|
|
725
|
-
* //Returns &this=that&hello=world
|
|
726
|
-
* sdk.utils.mapParameters({"this":"that", "hello":"world"})
|
|
727
|
-
*/
|
|
728
|
-
service.mapParameters = function(parameters) {
|
|
729
|
-
|
|
730
|
-
parameters = parameters || {}
|
|
731
|
-
|
|
732
|
-
var array = [];
|
|
733
|
-
|
|
734
|
-
Object.entries(parameters)
|
|
735
|
-
.forEach(function([key, value]) {
|
|
736
|
-
|
|
737
|
-
if (value === undefined || value === null || value == false) {
|
|
738
|
-
return;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
if (Array.isArray(value)) {
|
|
742
|
-
value.forEach(function(v) {
|
|
743
|
-
array.push(`${key}=${encodeURIComponent(v)}`);
|
|
744
|
-
})
|
|
745
|
-
} else {
|
|
746
|
-
array.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
})
|
|
750
|
-
|
|
751
|
-
return array.join('&');
|
|
752
|
-
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
* A function that will take an integer and a currency string and return a formatted numeric amount rounded to 2 decimal places
|
|
759
|
-
* @alias utils.formatCurrency
|
|
760
|
-
* @param {Integer} value The amount in cents
|
|
761
|
-
* @param {String} currency The currency to format
|
|
762
|
-
* @return {String} The formatted value
|
|
763
|
-
* @example
|
|
764
|
-
*
|
|
765
|
-
* //Returns £10.00
|
|
766
|
-
* sdk.utils.formatCurrency(1000, 'gbp');
|
|
767
|
-
*
|
|
768
|
-
* //Returns $10.00
|
|
769
|
-
* sdk.utils.formatCurrency(1000, 'usd');
|
|
770
|
-
*
|
|
771
|
-
*/
|
|
772
|
-
service.formatCurrency = function(value, currency) {
|
|
773
|
-
|
|
774
|
-
if (!value || isNaN(value)) {
|
|
775
|
-
value = 0;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
var currencyPrefix = service.currencySymbol(currency);
|
|
779
|
-
return `${currencyPrefix}${parseFloat(parseInt(value) / 100).toFixed(2)}`;
|
|
780
|
-
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
/**
|
|
786
|
-
* A function that will take an id and return the type key
|
|
787
|
-
* @alias utils.getTypeFromID
|
|
788
|
-
* @param {String} id The id of an object
|
|
789
|
-
* @return {String} The key
|
|
790
|
-
* @example
|
|
791
|
-
*
|
|
792
|
-
* // Returns 'user'
|
|
793
|
-
* sdk.utils.getTypeFromID('52b523f775beea960013f6cd');
|
|
794
|
-
*
|
|
795
|
-
* // Returns 'role'
|
|
796
|
-
* sdk.utils.getTypeFromID('62b59cb572fb4772e7b5fa93');
|
|
797
|
-
*
|
|
798
|
-
*/
|
|
799
|
-
service.getTypeFromID = function(id) {
|
|
800
|
-
|
|
801
|
-
id = service.id(id);
|
|
802
|
-
|
|
803
|
-
if (!id) {
|
|
804
|
-
return;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
const lookup = {
|
|
808
|
-
"21": "organisation",
|
|
809
|
-
"23": "comment",
|
|
810
|
-
"24": "persona",
|
|
811
|
-
"25": "audio",
|
|
812
|
-
"26": "campaign",
|
|
813
|
-
"28": "smartlist",
|
|
814
|
-
"29": "cache",
|
|
815
|
-
"40": "application",
|
|
816
|
-
"41": "action",
|
|
817
|
-
"42": "billinginvoice",
|
|
818
|
-
"43": "componentsnapshot",
|
|
819
|
-
"44": "diff",
|
|
820
|
-
"45": "email",
|
|
821
|
-
"46": "submission",
|
|
822
|
-
"49": "import",
|
|
823
|
-
"53": "socket",
|
|
824
|
-
"54": "timetrigger",
|
|
825
|
-
"61": "article",
|
|
826
|
-
"63": "component",
|
|
827
|
-
"65": "event",
|
|
828
|
-
"66": "file",
|
|
829
|
-
"67": "tag",
|
|
830
|
-
"69": "image",
|
|
831
|
-
"70": "profile",
|
|
832
|
-
"72": "role",
|
|
833
|
-
"73": "scope",
|
|
834
|
-
"74": "transaction",
|
|
835
|
-
"75": "user",
|
|
836
|
-
"76": "video",
|
|
837
|
-
"77": "workflowcard",
|
|
838
|
-
"78": "variable",
|
|
839
|
-
"3c": "patoken",
|
|
840
|
-
"7b": "uatoken",
|
|
841
|
-
"7d": "urtoken",
|
|
842
|
-
"2d": "systemtask",
|
|
843
|
-
"3d": "export",
|
|
844
|
-
"5f": "systemflag",
|
|
845
|
-
"2b": "batch",
|
|
846
|
-
"3a": "log",
|
|
847
|
-
"2e": "stat",
|
|
848
|
-
"2f": "unsubscribe",
|
|
849
|
-
"6b": "intent",
|
|
850
|
-
"7c": "upload",
|
|
851
|
-
"2c": "systemtrigger",
|
|
852
|
-
"6e": "interface",
|
|
853
|
-
"4e": "interfacesnapshot",
|
|
854
|
-
"4f": "notification",
|
|
855
|
-
"2a": "definition",
|
|
856
|
-
"7e": "definitionsnapshot",
|
|
857
|
-
"5e": "integration",
|
|
858
|
-
"4c": "listener",
|
|
859
|
-
"6d": "topic",
|
|
860
|
-
"7a": "code",
|
|
861
|
-
"4d": "paymentmethod",
|
|
862
|
-
"6c": "sslcertificate"
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
var hexKey = id.slice(8, 10);
|
|
866
|
-
return lookup[hexKey];
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
* A function that will take a currency string and return the symbol
|
|
872
|
-
* @alias utils.currencySymbol
|
|
873
|
-
* @param {String} currency The currency
|
|
874
|
-
* @return {String} The symbol
|
|
875
|
-
* @example
|
|
876
|
-
*
|
|
877
|
-
* //Returns £
|
|
878
|
-
* sdk.utils.currencySymbol('gbp');
|
|
879
|
-
*
|
|
880
|
-
* //Returns $
|
|
881
|
-
* sdk.utils.currencySymbol('usd');
|
|
882
|
-
*
|
|
883
|
-
*/
|
|
884
|
-
service.currencySymbol = function(currency) {
|
|
885
|
-
//Ensure lowercase currency
|
|
886
|
-
currency = String(currency).toLowerCase();
|
|
887
|
-
|
|
888
|
-
switch (String(currency).toLowerCase()) {
|
|
889
|
-
case 'gbp':
|
|
890
|
-
return '£';
|
|
891
|
-
break;
|
|
892
|
-
case 'eur':
|
|
893
|
-
return '€';
|
|
894
|
-
break;
|
|
895
|
-
default:
|
|
896
|
-
return '$';
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
service.getAvailableCurrencies = function(DefaultCountryID) {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
var array = [];
|
|
907
|
-
|
|
908
|
-
array.push({
|
|
909
|
-
name: `USD (${service.currencySymbol("usd")})`,
|
|
910
|
-
value: "usd",
|
|
911
|
-
countryCode: { 'US': true },
|
|
912
|
-
});
|
|
913
|
-
|
|
914
|
-
array.push({
|
|
915
|
-
name: `GBP (${service.currencySymbol("gbp")})`,
|
|
916
|
-
value: "gbp",
|
|
917
|
-
countryCode: { 'GB': true, 'UK': true },
|
|
918
|
-
});
|
|
919
|
-
|
|
920
|
-
array.push({
|
|
921
|
-
name: `CAD (${service.currencySymbol("cad")})`,
|
|
922
|
-
value: "cad",
|
|
923
|
-
countryCode: { 'CA': true },
|
|
924
|
-
});
|
|
925
|
-
|
|
926
|
-
array.push({
|
|
927
|
-
name: `AUD (${service.currencySymbol("aud")})`,
|
|
928
|
-
value: "aud",
|
|
929
|
-
countryCode: { 'AU': true },
|
|
930
|
-
});
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
array.push({
|
|
934
|
-
name: `NZD (${service.currencySymbol("nzd")})`,
|
|
935
|
-
value: "nzd",
|
|
936
|
-
countryCode: { 'NZ': true },
|
|
937
|
-
});
|
|
938
|
-
|
|
939
|
-
array.push({
|
|
940
|
-
name: `SGD (${service.currencySymbol("sgd")})`,
|
|
941
|
-
value: "sgd",
|
|
942
|
-
countryCode: { 'SG': true },
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
if (DefaultCountryID) {
|
|
947
|
-
|
|
948
|
-
var findMatch = array.findIndex(function(currency) {
|
|
949
|
-
return currency.countryCode[DefaultCountryID];
|
|
950
|
-
})
|
|
951
|
-
|
|
952
|
-
const moveArrayItem = (array, fromIndex, toIndex) => {
|
|
953
|
-
const arr = [...array];
|
|
954
|
-
arr.splice(toIndex, 0, ...arr.splice(fromIndex, 1));
|
|
955
|
-
return arr;
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
if (findMatch != -1) {
|
|
959
|
-
array = moveArrayItem(array, findMatch, 0)
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
return array;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
967
|
-
|
|
968
|
-
/**
|
|
969
|
-
* Creates a fast keyed hash object from an array of items
|
|
970
|
-
* @alias utils.hash
|
|
971
|
-
* @param {Array} array The array of items to convert into a hash
|
|
972
|
-
* @param {String} key The key or path to the property on each item to use as the hashed key
|
|
973
|
-
* @return {Object} A key/value paired object
|
|
974
|
-
* @example
|
|
975
|
-
* //Returns { jimbo:{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'} }
|
|
976
|
-
* sdk.utils.hash([{id:'jimbo', title:'Jim Jones'}, {id:'roger', title:'Roger Fellow'}], 'id');
|
|
977
|
-
*
|
|
978
|
-
*/
|
|
979
|
-
service.hash = function(items, key) {
|
|
980
|
-
items = !Array.isArray(items) ? [] : items;
|
|
981
|
-
return items.reduce(function(memo, item) {
|
|
982
|
-
const k = _get(item, key);
|
|
983
|
-
memo[k] = item;
|
|
984
|
-
return memo;
|
|
985
|
-
}, {});
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
//////////////////////////////////////////////////
|
|
992
|
-
|
|
993
|
-
/**
|
|
994
|
-
* Returns a subset of values in an array that match a provided rule
|
|
995
|
-
* @alias utils.extractFromArray
|
|
996
|
-
* @param {Array} array The array you want to extract values from
|
|
997
|
-
* @param {String} key The path to the child property you want to extract
|
|
998
|
-
* @param {Boolean} sum Whether to sum the extracted values together in total
|
|
999
|
-
* @param {Boolean} flatten Whether to flatten nested child arrays
|
|
1000
|
-
* @param {Boolean} unique Whether to only return unique values
|
|
1001
|
-
* @param {Boolean} exclude Whether to exclude null or undefined values
|
|
1002
|
-
* @param {Object} options Pass through extra options for how to extract the values
|
|
1003
|
-
* @return {Array} An array of all values retrieved from the array, unless provided arguments require otherwise
|
|
1004
|
-
* @example
|
|
1005
|
-
* //Returns [12, 45] as all the values
|
|
1006
|
-
* sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:45}], 'age');
|
|
1007
|
-
*
|
|
1008
|
-
* //Returns 32
|
|
1009
|
-
* sdk.utils.extractFromArray([{name:'Wendy', age:12}, {name:'Roger', age:20}], 'age', {sum:true});
|
|
1010
|
-
*
|
|
1011
|
-
*/
|
|
1012
|
-
service.extractFromArray = function(array, key, sum, flatten, unique, exclude, options) {
|
|
1013
|
-
|
|
1014
|
-
options = options || {}
|
|
1015
|
-
|
|
1016
|
-
if (sum) {
|
|
1017
|
-
options.sum = sum;
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
if (flatten) {
|
|
1021
|
-
options.flatten = true;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
if (unique) {
|
|
1025
|
-
options.unique = true;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
if (exclude) {
|
|
1029
|
-
options.excludeNull = true;
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
/////////////////
|
|
1033
|
-
|
|
1034
|
-
//Filter the array options by a certain value and operator
|
|
1035
|
-
var extractedValues = array.reduce(function(set, entry) {
|
|
1036
|
-
//Get the value from the object
|
|
1037
|
-
var retrievedValue = _get(entry, key);
|
|
1038
|
-
|
|
1039
|
-
var isNull = (!retrievedValue && (retrievedValue !== false && retrievedValue !== 0));
|
|
1040
|
-
if (options.excludeNull && isNull) {
|
|
1041
|
-
return set;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
set.push(retrievedValue);
|
|
1045
|
-
return set;
|
|
1046
|
-
}, [])
|
|
1047
|
-
|
|
1048
|
-
if (options.flatten) {
|
|
1049
|
-
extractedValues = _.flatten(extractedValues);
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
if (options.unique) {
|
|
1053
|
-
extractedValues = _.uniq(extractedValues);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
if (options.sum) {
|
|
1057
|
-
extractedValues = extractedValues.reduce(function(a, b) {
|
|
1058
|
-
return a + b;
|
|
1059
|
-
}, 0);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
return extractedValues;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
//////////////////////////////////////////////////////
|
|
1067
|
-
|
|
1068
|
-
/**
|
|
1069
|
-
* A function that can return a selection of values that were found in an array that match a specific rule,
|
|
1070
|
-
* This is often used to evaluate expressions within form fields
|
|
1071
|
-
* @alias utils.matchInArray
|
|
1072
|
-
* @param {Array} array The array to check
|
|
1073
|
-
* @param {String} key The javascript dot notation path to extract
|
|
1074
|
-
* @param {String} value The value to compare against
|
|
1075
|
-
* @param {String} comparator The logical operator to use to compare the extracted value with the provided value ('>', '<', '>=', '<=', 'in', '==') Defaults to '==' (Is equal to)
|
|
1076
|
-
* @return {Array} Returns an array of matching values
|
|
1077
|
-
* @example
|
|
1078
|
-
* //Returns [{name:'Michael', age:45}] as that is only item in the array that matches the criteria
|
|
1079
|
-
* sdk.utils.matchInArray([{name:'Wendy', age:12}, {name:'Michael', age:45}], 'age', 45, '>=');
|
|
1080
|
-
*
|
|
1081
|
-
*/
|
|
1082
|
-
service.matchInArray = function(array, key, v, comparator) {
|
|
1083
|
-
|
|
1084
|
-
//Filter the array options by a certain v and comparator
|
|
1085
|
-
var matches = array.filter(function(entry) {
|
|
1086
|
-
//Get the v from the object
|
|
1087
|
-
var extracted = _get(entry, key);
|
|
1088
|
-
var found;
|
|
1089
|
-
|
|
1090
|
-
switch (comparator) {
|
|
1091
|
-
case 'in':
|
|
1092
|
-
found = extracted.includes(v);
|
|
1093
|
-
break;
|
|
1094
|
-
case '>=':
|
|
1095
|
-
found = (extracted >= v);
|
|
1096
|
-
break;
|
|
1097
|
-
case '<=':
|
|
1098
|
-
found = (extracted <= v);
|
|
1099
|
-
break;
|
|
1100
|
-
case '<':
|
|
1101
|
-
found = (extracted < v);
|
|
1102
|
-
break;
|
|
1103
|
-
case '>':
|
|
1104
|
-
found = (extracted > v);
|
|
1105
|
-
break;
|
|
1106
|
-
case '==':
|
|
1107
|
-
default:
|
|
1108
|
-
if (v === undefined) {
|
|
1109
|
-
found = extracted;
|
|
1110
|
-
} else {
|
|
1111
|
-
found = (extracted == v);
|
|
1112
|
-
}
|
|
1113
|
-
break;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
return found;
|
|
1117
|
-
})
|
|
1118
|
-
|
|
1119
|
-
return matches;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
1123
|
-
|
|
1124
|
-
/**
|
|
1125
|
-
* A helpful class that can take an array of values and return them as a comma seperated
|
|
1126
|
-
* string, If the values are objects, then a property to use as the string representation can be specified
|
|
1127
|
-
* @alias utils.comma
|
|
1128
|
-
* @param {Array} array The array of values to translate
|
|
1129
|
-
* @param {String} path An optional property key to use for each value
|
|
1130
|
-
* @return {String} The resulting comma seperated string
|
|
1131
|
-
* @example
|
|
1132
|
-
* //Returns 'cat, dog, bird'
|
|
1133
|
-
* sdk.utils.comma(['cat', 'dog', 'bird']);
|
|
1134
|
-
*
|
|
1135
|
-
* //Returns 'cat, dog, bird'
|
|
1136
|
-
* sdk.utils.comma([{title:'cat'}, {title:'dog'}, {title:'bird'}], 'title');
|
|
1137
|
-
*/
|
|
1138
|
-
service.comma = function(array, path, limit) {
|
|
1139
|
-
|
|
1140
|
-
if (limit) {
|
|
1141
|
-
array = array.slice(0, limit);
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
return _.chain(array)
|
|
1145
|
-
.compact()
|
|
1146
|
-
.map(function(item) {
|
|
1147
|
-
if (path && path.length) {
|
|
1148
|
-
return _get(item, path);
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
return item;
|
|
1152
|
-
})
|
|
1153
|
-
.value()
|
|
1154
|
-
.join(', ');
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
1158
|
-
|
|
1159
|
-
//Helper function to get an id of an object
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* Returns a specified _id for an object
|
|
1163
|
-
* @alias utils.id
|
|
1164
|
-
* @param {Object} input An object that is or has an _id property
|
|
1165
|
-
* @param {Boolean} asObjectID Whether to convert to a Mongo ObjectId
|
|
1166
|
-
* @return {String} Will return either a string or a Mongo ObjectId
|
|
1167
|
-
*
|
|
1168
|
-
* @example
|
|
1169
|
-
*
|
|
1170
|
-
* //Returns '5cb3d8b3a2219970e6f86927'
|
|
1171
|
-
* sdk.utils.id('5cb3d8b3a2219970e6f86927')
|
|
1172
|
-
*
|
|
1173
|
-
* //Returns true
|
|
1174
|
-
* typeof service.id({_id:'5cb3d8b3a2219970e6f86927', title, ...}) == 'string';
|
|
1175
|
-
|
|
1176
|
-
* //Returns true
|
|
1177
|
-
* typeof service.id({_id:'5cb3d8b3a2219970e6f86927'}, true) == 'object';
|
|
1178
|
-
*/
|
|
1179
|
-
service.id = function(source) {
|
|
1180
|
-
|
|
1181
|
-
if (!source) {
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/////////////////////////////////
|
|
1186
|
-
|
|
1187
|
-
var output;
|
|
1188
|
-
|
|
1189
|
-
if (source._id) {
|
|
1190
|
-
output = String(source._id);
|
|
1191
|
-
} else {
|
|
1192
|
-
output = String(source);
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
var isValid = service.isValidID(output);
|
|
1197
|
-
if (!isValid) {
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
return output;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
1205
|
-
|
|
1206
|
-
/**
|
|
1207
|
-
* Cleans and maps an array of objects to an array of IDs
|
|
1208
|
-
* @alias utils.ids
|
|
1209
|
-
* @param {Array} array An array of objects or object ids
|
|
1210
|
-
* @param {Boolean} asObjectID Whether or not to map the ids as Mongo ObjectIds
|
|
1211
|
-
* @return {Array} An array of Ids
|
|
1212
|
-
*
|
|
1213
|
-
* @example
|
|
1214
|
-
* //Returns ['5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927']
|
|
1215
|
-
* sdk.utils.ids([{_id:'5cb3d8b3a2219970e6f86927'}, {_id:'5cb3d8b3a2219970e6f86927'}, null, '5cb3d8b3a2219970e6f86927'])
|
|
1216
|
-
*/
|
|
1217
|
-
|
|
1218
|
-
service.ids = function(array) {
|
|
1219
|
-
|
|
1220
|
-
if (!array) {
|
|
1221
|
-
return [];
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
/////////////////////////////////
|
|
1225
|
-
|
|
1226
|
-
var ids = Object.keys(array.reduce(function(set, entry) {
|
|
1227
|
-
|
|
1228
|
-
if (!entry) {
|
|
1229
|
-
return set;
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
var cleaned = service.id(entry)
|
|
1233
|
-
|
|
1234
|
-
if (cleaned) {
|
|
1235
|
-
set[cleaned] = 1;
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
return set;
|
|
1239
|
-
}, {}))
|
|
1240
|
-
|
|
1241
|
-
///////////////////////////////
|
|
1242
|
-
|
|
1243
|
-
return ids;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
1248
|
-
|
|
1249
|
-
service.isValidID = function(input) {
|
|
1250
|
-
var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$")
|
|
1251
|
-
return checkForHexRegExp.test(String(input));
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
1256
|
-
|
|
1257
|
-
/**
|
|
1258
|
-
* Helper function for retrieving a human readable error message from server error response objects
|
|
1259
|
-
* @alias utils.errorMessage
|
|
1260
|
-
* @param {Object} error The error object to translate
|
|
1261
|
-
* @return {String} The resulting human readable error message
|
|
1262
|
-
*/
|
|
1263
|
-
service.errorMessage = function(err) {
|
|
1264
|
-
|
|
1265
|
-
if (!err) {
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
if (Array.isArray(err)) {
|
|
1271
|
-
err = err[0];
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
////////////////////////////////////
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
var candidates = [
|
|
1278
|
-
'response.data.message',
|
|
1279
|
-
'response.data',
|
|
1280
|
-
'message',
|
|
1281
|
-
]
|
|
1282
|
-
|
|
1283
|
-
var message;
|
|
1284
|
-
|
|
1285
|
-
candidates.forEach(function(path) {
|
|
1286
|
-
if (message) {
|
|
1287
|
-
return;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
var m = _get(err, path);
|
|
1291
|
-
if (m) {
|
|
1292
|
-
message = m;
|
|
1293
|
-
}
|
|
1294
|
-
})
|
|
1295
|
-
|
|
1296
|
-
if (Array.isArray(message)) {
|
|
1297
|
-
message = message[0];
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
////////////////////////////////////
|
|
1301
|
-
|
|
1302
|
-
message = message || JSON.stringify(err);
|
|
1303
|
-
|
|
1304
|
-
////////////////////////////////////
|
|
1305
|
-
|
|
1306
|
-
return message;
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
////////////////////////////////////
|
|
1310
|
-
|
|
1311
|
-
/**
|
|
1312
|
-
* Generates a globally unique ID, helpful for adding unique keys for iterable loops
|
|
1313
|
-
* @alias utils.guid
|
|
1314
|
-
* @return {String} The new globally unique identifier
|
|
1315
|
-
* @example
|
|
1316
|
-
* //Returns 4323a78br-z16h-289j-zwl1-938lda334asd
|
|
1317
|
-
* sdk.utils.guid()
|
|
1318
|
-
*/
|
|
1319
|
-
service.guid = function() {
|
|
1320
|
-
var u = (new Date()).getTime().toString(16) + Math.random().toString(16).substring(2) + "0".repeat(16);
|
|
1321
|
-
return u.substr(0, 8) + '-' + u.substr(8, 4) + '-4000-8' + u.substr(12, 3) + '-' + u.substr(15, 12);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
////////////////////////////////////
|
|
1328
|
-
////////////////////////////////////
|
|
1329
|
-
////////////////////////////////////
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* Helper function for cleaning strings to use as database ids
|
|
1333
|
-
* @alias utils.machineName
|
|
1334
|
-
* @param {String} string The string to clean eg. (Awesome Event!)
|
|
1335
|
-
* @return {String} A cleaned and formatted string eg. (awesomeEvent)
|
|
1336
|
-
*/
|
|
1337
|
-
service.machineName = function(string) {
|
|
1338
|
-
if (!string || !string.length) {
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
var regexp = /[^a-zA-Z0-9-_]+/g;
|
|
1343
|
-
var cleaned = String(string).replace(regexp, ' ');
|
|
1344
|
-
return _camelCase(cleaned);
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
/////////////////////////////////////////////
|
|
1348
|
-
/////////////////////////////////////////////
|
|
1349
|
-
/////////////////////////////////////////////
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
export default service;
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
/////////////////////////////////////////////
|
|
1356
|
-
|
|
1357
|
-
//Export the event dispatcher
|
|
1358
|
-
export function EventDispatcher() {
|
|
1359
|
-
|
|
1360
|
-
var listeners = {};
|
|
1361
|
-
|
|
1362
|
-
/////////////////////////////////////////////
|
|
1363
|
-
|
|
1364
|
-
var dispatcher = {}
|
|
1365
|
-
|
|
1366
|
-
/////////////////////////////////////////////
|
|
1367
|
-
|
|
1368
|
-
//Remove all listeners
|
|
1369
|
-
dispatcher.removeAllListeners = function() {
|
|
1370
|
-
listeners = {};
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
/////////////////////////////////////////////
|
|
1374
|
-
|
|
1375
|
-
dispatcher.dispatch = function(event, details) {
|
|
1376
|
-
|
|
1377
|
-
if (listeners[event]) {
|
|
1378
|
-
//For each listener
|
|
1379
|
-
listeners[event].forEach(function(callback) {
|
|
1380
|
-
return callback(details);
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
/////////////////////////////////////////////
|
|
1386
|
-
|
|
1387
|
-
dispatcher.addEventListener = function(event, callback) {
|
|
1388
|
-
|
|
1389
|
-
if (!listeners[event]) {
|
|
1390
|
-
listeners[event] = [];
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
const type = typeof callback;
|
|
1394
|
-
if (type !== 'function') {
|
|
1395
|
-
throw new Error(`addEventListener() requires a function but ${type} was added`);
|
|
1396
|
-
} else {
|
|
1397
|
-
if (listeners[event].indexOf(callback) == -1) {
|
|
1398
|
-
//Add to the listeners
|
|
1399
|
-
listeners[event].push(callback)
|
|
1400
|
-
} else {
|
|
1401
|
-
//A
|
|
1402
|
-
//lready listening
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
/////////////////////////////////////////////
|
|
1408
|
-
|
|
1409
|
-
dispatcher.removeEventListener = function(event, callback) {
|
|
1410
|
-
|
|
1411
|
-
if (!listeners[event]) {
|
|
1412
|
-
listeners[event] = [];
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
//Get the index of the listener
|
|
1416
|
-
var index = listeners[event].indexOf(callback);
|
|
1417
|
-
|
|
1418
|
-
if (index != -1) {
|
|
1419
|
-
//Remove from the listeners
|
|
1420
|
-
listeners[event].splice(index, 1);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
/////////////////////////////////////////////
|
|
1426
|
-
|
|
1427
|
-
//Wrap the event listener functionality
|
|
1428
|
-
dispatcher.bootstrap = function(service) {
|
|
1429
|
-
if (!service) {
|
|
1430
|
-
// console.log('No service to bootstrap to')
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
service.dispatch = dispatcher.dispatch;
|
|
1435
|
-
service.addEventListener = dispatcher.addEventListener;
|
|
1436
|
-
service.removeEventListener = dispatcher.removeEventListener;
|
|
1437
|
-
service.removeAllListeners = dispatcher.removeAllListeners;
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
/////////////////////////////////////////////
|
|
1441
|
-
|
|
1442
|
-
return dispatcher;
|
|
1443
|
-
}</code></pre>
|
|
1444
|
-
</article>
|
|
1445
|
-
</section>
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
</div>
|
|
1453
|
-
|
|
1454
|
-
<br class="clear">
|
|
1455
|
-
|
|
1456
|
-
<footer>
|
|
1457
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Thu Sep 28 2023 07:24:39 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1458
|
-
</footer>
|
|
1459
|
-
|
|
1460
|
-
<script>prettyPrint();</script>
|
|
1461
|
-
<script src="scripts/polyfill.js"></script>
|
|
1462
|
-
<script src="scripts/linenumber.js"></script>
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
</body>
|
|
1467
|
-
</html>
|