@reldens/utils 0.12.0 → 0.15.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/shortcuts.js +39 -0
- package/package.json +1 -1
package/lib/shortcuts.js
CHANGED
|
@@ -32,6 +32,11 @@ class Shortcuts
|
|
|
32
32
|
return Array.isArray(obj);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
isFunction(object, property)
|
|
36
|
+
{
|
|
37
|
+
return 'function' === typeof object[property];
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
length(obj)
|
|
36
41
|
{
|
|
37
42
|
if(!obj){
|
|
@@ -136,6 +141,40 @@ class Shortcuts
|
|
|
136
141
|
return date.toISOString().slice(0, 19).replace('T', ' ');
|
|
137
142
|
}
|
|
138
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
|
+
return this.randomString(length, false);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
randomCharsWithSymbols(length)
|
|
158
|
+
{
|
|
159
|
+
if(0 >= length){
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
return this.randomString(length, true);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
randomString(length, withSymbols = false)
|
|
166
|
+
{
|
|
167
|
+
let result = '';
|
|
168
|
+
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
169
|
+
if(withSymbols){
|
|
170
|
+
characters += '!@#$%&*()_-=+[]{}:;<>,./?';
|
|
171
|
+
}
|
|
172
|
+
let charactersLength = characters.length;
|
|
173
|
+
for (let i = 0; i < length; i++) {
|
|
174
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
139
178
|
}
|
|
140
179
|
|
|
141
180
|
module.exports = new Shortcuts();
|