@reldens/utils 0.45.0 → 0.47.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/README.md +4 -1
- package/index.js +1 -0
- package/lib/page-range-provider.js +38 -0
- package/lib/shortcuts.js +22 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
### Features
|
|
6
6
|
|
|
7
7
|
- Interaction area calculation helper.
|
|
8
|
+
- Page range provider helper.
|
|
9
|
+
- A validator interface and the SchemaValidator.
|
|
10
|
+
- EnvVar for cast variables.
|
|
8
11
|
- Shortcuts.
|
|
9
12
|
- Logger.
|
|
10
13
|
- Error Manager.
|
|
11
|
-
- Events Manager.
|
|
14
|
+
- Events Manager and Events Manager Singleton.
|
|
12
15
|
|
|
13
16
|
Need something specific?
|
|
14
17
|
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ module.exports = {
|
|
|
11
11
|
EventsManagerSingleton: new EventsManager(),
|
|
12
12
|
ErrorManager: require('./lib/error-manager'),
|
|
13
13
|
InteractionArea: require('./lib/interaction-area'),
|
|
14
|
+
PageRangeProvider: require('./lib/page-range-provider'),
|
|
14
15
|
ValidatorInterface: require('./lib/validator-interface'),
|
|
15
16
|
SchemaValidator: require('./lib/schema-validator'),
|
|
16
17
|
EnvVar: require('./lib/env-var'),
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - PageRangeProvider
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
class PageRangeProvider
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
fetch(page, totalPages, totalDisplayedPages = 5, firstLabel = 'first', lastLabel = 'last')
|
|
11
|
+
{
|
|
12
|
+
let half = Math.floor(totalDisplayedPages / 2);
|
|
13
|
+
let start = page - half;
|
|
14
|
+
let end = page + half;
|
|
15
|
+
start = Math.max(1, start);
|
|
16
|
+
end = Math.min(totalPages, end);
|
|
17
|
+
if(end - start + 1 < totalDisplayedPages){
|
|
18
|
+
if(start === 1){
|
|
19
|
+
end = Math.min(totalPages, start + totalDisplayedPages - 1);
|
|
20
|
+
}
|
|
21
|
+
start = Math.max(1, end - totalDisplayedPages + 1);
|
|
22
|
+
}
|
|
23
|
+
let range = [];
|
|
24
|
+
if(1 < start){
|
|
25
|
+
range.push({label: firstLabel, value: 1});
|
|
26
|
+
}
|
|
27
|
+
for(let i = start; i <= end; i++){
|
|
28
|
+
range.push({label: i, value: i});
|
|
29
|
+
}
|
|
30
|
+
if(end < totalPages){
|
|
31
|
+
range.push({label: lastLabel, value: totalPages - 1});
|
|
32
|
+
}
|
|
33
|
+
return range;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = new PageRangeProvider();
|
package/lib/shortcuts.js
CHANGED
|
@@ -47,6 +47,11 @@ class Shortcuts
|
|
|
47
47
|
return -1 !== dataArray.indexOf(value);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
isNotEmptyArray(dataArray)
|
|
51
|
+
{
|
|
52
|
+
return (this.isArray(dataArray) && 0 < dataArray.length);
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
isFunction(callback)
|
|
51
56
|
{
|
|
52
57
|
return (callback && 'function' === typeof callback);
|
|
@@ -302,7 +307,7 @@ class Shortcuts
|
|
|
302
307
|
let obj = {};
|
|
303
308
|
for(let [key, value] of formData){
|
|
304
309
|
if(obj[key] !== undefined){
|
|
305
|
-
if(!
|
|
310
|
+
if(!this.isArray(obj[key])){
|
|
306
311
|
obj[key] = [obj[key]];
|
|
307
312
|
}
|
|
308
313
|
obj[key].push(value);
|
|
@@ -458,6 +463,22 @@ class Shortcuts
|
|
|
458
463
|
.replace(/vbscript:/gi, '');
|
|
459
464
|
}
|
|
460
465
|
|
|
466
|
+
camelCase(str)
|
|
467
|
+
{
|
|
468
|
+
return str.replace(/[_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
capitalizedCamelCase(str)
|
|
472
|
+
{
|
|
473
|
+
let camelStr = this.camelCase(str);
|
|
474
|
+
return camelStr.charAt(0).toUpperCase() + camelStr.slice(1);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
kebabCase(str)
|
|
478
|
+
{
|
|
479
|
+
return str.replace(/[_\s]+/g, '-');
|
|
480
|
+
}
|
|
481
|
+
|
|
461
482
|
}
|
|
462
483
|
|
|
463
484
|
module.exports = new Shortcuts();
|