@reldens/utils 0.13.0 → 0.16.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
|
@@ -141,6 +141,45 @@ class Shortcuts
|
|
|
141
141
|
return date.toISOString().slice(0, 19).replace('T', ' ');
|
|
142
142
|
}
|
|
143
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
|
+
}
|
|
178
|
+
|
|
179
|
+
numberWithDecimals(number, decimals = 0)
|
|
180
|
+
{
|
|
181
|
+
return Number(Number(number).toFixed(decimals));
|
|
182
|
+
}
|
|
144
183
|
}
|
|
145
184
|
|
|
146
185
|
module.exports = new Shortcuts();
|