@reldens/utils 0.14.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 +17 -2
- package/package.json +1 -1
package/lib/shortcuts.js
CHANGED
|
@@ -151,15 +151,30 @@ class Shortcuts
|
|
|
151
151
|
if(0 >= length){
|
|
152
152
|
return '';
|
|
153
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
|
+
{
|
|
154
167
|
let result = '';
|
|
155
168
|
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
169
|
+
if(withSymbols){
|
|
170
|
+
characters += '!@#$%&*()_-=+[]{}:;<>,./?';
|
|
171
|
+
}
|
|
156
172
|
let charactersLength = characters.length;
|
|
157
|
-
for(let i=0; i < length; i++){
|
|
173
|
+
for (let i = 0; i < length; i++) {
|
|
158
174
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
159
175
|
}
|
|
160
176
|
return result;
|
|
161
177
|
}
|
|
162
|
-
|
|
163
178
|
}
|
|
164
179
|
|
|
165
180
|
module.exports = new Shortcuts();
|