@reldens/utils 0.41.0 → 0.42.0
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/lib/error-manager.js +5 -3
- package/lib/events-manager.js +4 -4
- package/lib/interaction-area.js +5 -8
- package/lib/schema-validator.js +4 -2
- package/lib/shortcuts.js +31 -0
- package/lib/validator-interface.js +17 -0
- package/package.json +1 -1
package/lib/error-manager.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
*
|
|
3
3
|
* Reldens - ErrorManager
|
|
4
4
|
*
|
|
5
|
-
* This module handle all the game errors.
|
|
6
|
-
*
|
|
7
5
|
*/
|
|
8
6
|
|
|
9
7
|
class ErrorManager
|
|
@@ -12,14 +10,18 @@ class ErrorManager
|
|
|
12
10
|
constructor()
|
|
13
11
|
{
|
|
14
12
|
this.enableTrace = false;
|
|
13
|
+
this.callback = false;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
error(message)
|
|
18
17
|
{
|
|
19
|
-
// @TODO - BETA.17: evaluate better ways to handle errors, implement email notifications, etc.
|
|
20
18
|
if(this.enableTrace){
|
|
21
19
|
console.trace();
|
|
22
20
|
}
|
|
21
|
+
if('function' === typeof this.callback){
|
|
22
|
+
// use the callback to implement any customization here:
|
|
23
|
+
return this.callback(message);
|
|
24
|
+
}
|
|
23
25
|
throw new Error(message);
|
|
24
26
|
}
|
|
25
27
|
|
package/lib/events-manager.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* event will be referenced in a new property called "eventsByRemoveKey" so you can detach multiple listeners at the
|
|
9
9
|
* time.
|
|
10
10
|
*
|
|
11
|
-
* -
|
|
11
|
+
* - We override the "on" and "off" aliases override to include a debug check with a log. Using the debug property,
|
|
12
12
|
* you can specify to log "all" the fire and listeners, or just by key. Note the key search will be applied in both
|
|
13
13
|
* directions, it will check if the debug value exists in the event key or if the event key exists in the debug value.
|
|
14
14
|
*
|
|
@@ -133,9 +133,9 @@ class AwaitEventEmitterExtended extends AwaitEventEmitter
|
|
|
133
133
|
logDebugEvent(key, type)
|
|
134
134
|
{
|
|
135
135
|
if(
|
|
136
|
-
this.debug.indexOf('all')
|
|
137
|
-
|| this.debug.indexOf(key)
|
|
138
|
-
|| key.indexOf(this.debug)
|
|
136
|
+
-1 !== this.debug.indexOf('all')
|
|
137
|
+
|| -1 !== this.debug.indexOf(key)
|
|
138
|
+
|| -1 !== key.indexOf(this.debug)
|
|
139
139
|
){
|
|
140
140
|
Logger.debug(type+' Event:', key);
|
|
141
141
|
}
|
package/lib/interaction-area.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
*
|
|
3
3
|
* Reldens - InteractionArea
|
|
4
4
|
*
|
|
5
|
-
* This class is used to validate the area for a specific object or action
|
|
6
|
-
* by clicking on it and then
|
|
5
|
+
* This class is used to validate the area for a specific object or action. For example, if player A targets player B
|
|
6
|
+
* by clicking on it and then runs an action (by pressing space bar or using the action button), the action will
|
|
7
7
|
* be only valid and executed if player A is inside the interactive area of player B.
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
@@ -21,11 +21,11 @@ class InteractionArea
|
|
|
21
21
|
|
|
22
22
|
setupInteractionArea(margin = false, x = false, y = false)
|
|
23
23
|
{
|
|
24
|
-
//
|
|
24
|
+
// the margin parameter can force the interaction area:
|
|
25
25
|
if(margin){
|
|
26
26
|
this.interactionArea = margin;
|
|
27
27
|
}
|
|
28
|
-
// if there's none interaction area just do nothing:
|
|
28
|
+
// if there's none interaction area, just do nothing:
|
|
29
29
|
if(!this.interactionArea){
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
@@ -51,10 +51,7 @@ class InteractionArea
|
|
|
51
51
|
|
|
52
52
|
getPosition()
|
|
53
53
|
{
|
|
54
|
-
return {
|
|
55
|
-
x: this.x,
|
|
56
|
-
y: this.y
|
|
57
|
-
}
|
|
54
|
+
return {x: this.x, y: this.y}
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
}
|
package/lib/schema-validator.js
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
*
|
|
3
3
|
* Reldens - SchemaValidator
|
|
4
4
|
*
|
|
5
|
-
* This module is to validate
|
|
5
|
+
* This module is to validate the object properties at runtime.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
const ValidatorInterface = require('./validator-interface');
|
|
9
10
|
const sc = require('./shortcuts');
|
|
10
11
|
const Logger = require('./logger');
|
|
11
12
|
|
|
12
|
-
class SchemaValidator
|
|
13
|
+
class SchemaValidator extends ValidatorInterface
|
|
13
14
|
{
|
|
14
15
|
|
|
15
16
|
constructor(schema)
|
|
16
17
|
{
|
|
18
|
+
super(schema);
|
|
17
19
|
this.schema = schema;
|
|
18
20
|
}
|
|
19
21
|
|
package/lib/shortcuts.js
CHANGED
|
@@ -427,6 +427,37 @@ class Shortcuts
|
|
|
427
427
|
return isoLanguageCodeRegex.test(isoCode);
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
+
sanitize(input)
|
|
431
|
+
{
|
|
432
|
+
if(!input){
|
|
433
|
+
return '';
|
|
434
|
+
}
|
|
435
|
+
return input
|
|
436
|
+
.replace(/&(?![a-zA-Z0-9#]+;)/g, '&')
|
|
437
|
+
.replace(/</g, '<')
|
|
438
|
+
.replace(/>/g, '>')
|
|
439
|
+
.replace(/"/g, '"')
|
|
440
|
+
.replace(/'/g, ''')
|
|
441
|
+
.replace(/\//g, '/')
|
|
442
|
+
.replace(/`/g, '`');
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
sanitizeUrl(url)
|
|
446
|
+
{
|
|
447
|
+
if(!url){
|
|
448
|
+
return '';
|
|
449
|
+
}
|
|
450
|
+
let sanitized = url.trim();
|
|
451
|
+
let urlPattern = /^(?:https?:\/\/|mailto:|tel:|#|\/|\.\/|\.\.\/)/i;
|
|
452
|
+
if(!urlPattern.test(sanitized)){
|
|
453
|
+
return '';
|
|
454
|
+
}
|
|
455
|
+
return sanitized
|
|
456
|
+
.replace(/javascript:/gi, '')
|
|
457
|
+
.replace(/data:/gi, '')
|
|
458
|
+
.replace(/vbscript:/gi, '');
|
|
459
|
+
}
|
|
460
|
+
|
|
430
461
|
}
|
|
431
462
|
|
|
432
463
|
module.exports = new Shortcuts();
|