@reldens/utils 0.11.0 → 0.14.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.
Files changed (2) hide show
  1. package/lib/shortcuts.js +43 -3
  2. package/package.json +1 -1
package/lib/shortcuts.js CHANGED
@@ -11,16 +11,15 @@ class Shortcuts
11
11
 
12
12
  hasOwn(obj, prop)
13
13
  {
14
- if(this.isArray(prop)){
14
+ if(this.isArray(prop) && 0 < prop.length){
15
15
  for(let value of prop){
16
16
  if(!(obj && {}.hasOwnProperty.call(obj, value))){
17
17
  return false;
18
18
  }
19
19
  }
20
20
  return true;
21
- } else {
22
- return (obj && {}.hasOwnProperty.call(obj, prop));
23
21
  }
22
+ return (obj && {}.hasOwnProperty.call(obj, prop));
24
23
  }
25
24
 
26
25
  isTrue(obj, prop, strictValidation)
@@ -33,8 +32,24 @@ class Shortcuts
33
32
  return Array.isArray(obj);
34
33
  }
35
34
 
35
+ isFunction(object, property)
36
+ {
37
+ return 'function' === typeof object[property];
38
+ }
39
+
40
+ length(obj)
41
+ {
42
+ if(!obj){
43
+ return 0;
44
+ }
45
+ return Object.keys(obj).length;
46
+ }
47
+
36
48
  convertObjectsArrayToObjectByKeys(dataArray, keyProperty)
37
49
  {
50
+ if(!this.isArray(dataArray) || 0 === dataArray.length){
51
+ return {};
52
+ }
38
53
  let objectByKeys = {};
39
54
  for(let arrayItem of dataArray){
40
55
  objectByKeys[arrayItem[keyProperty]] = arrayItem;
@@ -51,6 +66,9 @@ class Shortcuts
51
66
 
52
67
  propsAssign(from, to, props)
53
68
  {
69
+ if(!this.isArray(props)){
70
+ return to;
71
+ }
54
72
  for(let i of props){
55
73
  to[i] = from[i];
56
74
  }
@@ -91,6 +109,9 @@ class Shortcuts
91
109
 
92
110
  serializeFormData(formData)
93
111
  {
112
+ if(0 === formData.length){
113
+ return {};
114
+ }
94
115
  let obj = {};
95
116
  for(let [key, value] of formData){
96
117
  if(obj[key] !== undefined){
@@ -120,6 +141,25 @@ class Shortcuts
120
141
  return date.toISOString().slice(0, 19).replace('T', ' ');
121
142
  }
122
143
 
144
+ randomInteger(min, max)
145
+ {
146
+ return Math.floor(Math.random() * (max - min + 1)) + min;
147
+ }
148
+
149
+ randomChars(length)
150
+ {
151
+ if(0 >= length){
152
+ return '';
153
+ }
154
+ let result = '';
155
+ let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
156
+ let charactersLength = characters.length;
157
+ for(let i=0; i < length; i++){
158
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
159
+ }
160
+ return result;
161
+ }
162
+
123
163
  }
124
164
 
125
165
  module.exports = new Shortcuts();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.11.0",
4
+ "version": "0.14.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",