@augment-vir/common 26.0.0 → 26.0.2
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/dist/cjs/augments/random.js +47 -14
- package/dist/esm/augments/random.js +47 -14
- package/package.json +1 -1
|
@@ -11,8 +11,6 @@ function accessCrypto() {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
const crypto = accessCrypto();
|
|
14
|
-
// can't get this coverage to work
|
|
15
|
-
/* c8 ignore start */
|
|
16
14
|
/**
|
|
17
15
|
* Creates a random integer (decimal points are all cut off) between the given min and max
|
|
18
16
|
* (inclusive).
|
|
@@ -69,23 +67,58 @@ function createUuid() {
|
|
|
69
67
|
return crypto.randomUUID();
|
|
70
68
|
}
|
|
71
69
|
exports.createUuid = createUuid;
|
|
70
|
+
const validStringCharacters = [
|
|
71
|
+
'a',
|
|
72
|
+
'b',
|
|
73
|
+
'c',
|
|
74
|
+
'd',
|
|
75
|
+
'e',
|
|
76
|
+
'f',
|
|
77
|
+
'g',
|
|
78
|
+
'h',
|
|
79
|
+
'i',
|
|
80
|
+
'j',
|
|
81
|
+
'k',
|
|
82
|
+
'l',
|
|
83
|
+
'm',
|
|
84
|
+
'n',
|
|
85
|
+
'o',
|
|
86
|
+
'p',
|
|
87
|
+
'q',
|
|
88
|
+
'r',
|
|
89
|
+
's',
|
|
90
|
+
't',
|
|
91
|
+
'u',
|
|
92
|
+
'v',
|
|
93
|
+
'w',
|
|
94
|
+
'x',
|
|
95
|
+
'y',
|
|
96
|
+
'z',
|
|
97
|
+
0,
|
|
98
|
+
1,
|
|
99
|
+
2,
|
|
100
|
+
3,
|
|
101
|
+
4,
|
|
102
|
+
5,
|
|
103
|
+
6,
|
|
104
|
+
7,
|
|
105
|
+
8,
|
|
106
|
+
9,
|
|
107
|
+
];
|
|
72
108
|
/**
|
|
73
109
|
* Creates a random string (including letters and numbers) of a given length.
|
|
74
110
|
*
|
|
75
111
|
* This function uses cryptographically secure randomness.
|
|
76
112
|
*/
|
|
77
113
|
function randomString(inputLength = 16) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*/
|
|
88
|
-
.substring(0, inputLength));
|
|
114
|
+
let stringBuilder = '';
|
|
115
|
+
for (let i = 0; i < inputLength; i++) {
|
|
116
|
+
const index = randomInteger({
|
|
117
|
+
min: 0,
|
|
118
|
+
max: validStringCharacters.length - 1,
|
|
119
|
+
});
|
|
120
|
+
stringBuilder += validStringCharacters[index];
|
|
121
|
+
}
|
|
122
|
+
return stringBuilder;
|
|
89
123
|
}
|
|
90
124
|
exports.randomString = randomString;
|
|
91
|
-
/* c8 ignore stop */
|
|
@@ -8,8 +8,6 @@ function accessCrypto() {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
const crypto = accessCrypto();
|
|
11
|
-
// can't get this coverage to work
|
|
12
|
-
/* c8 ignore start */
|
|
13
11
|
/**
|
|
14
12
|
* Creates a random integer (decimal points are all cut off) between the given min and max
|
|
15
13
|
* (inclusive).
|
|
@@ -63,22 +61,57 @@ export function randomBoolean(percentLikelyToBeTrue = 50) {
|
|
|
63
61
|
export function createUuid() {
|
|
64
62
|
return crypto.randomUUID();
|
|
65
63
|
}
|
|
64
|
+
const validStringCharacters = [
|
|
65
|
+
'a',
|
|
66
|
+
'b',
|
|
67
|
+
'c',
|
|
68
|
+
'd',
|
|
69
|
+
'e',
|
|
70
|
+
'f',
|
|
71
|
+
'g',
|
|
72
|
+
'h',
|
|
73
|
+
'i',
|
|
74
|
+
'j',
|
|
75
|
+
'k',
|
|
76
|
+
'l',
|
|
77
|
+
'm',
|
|
78
|
+
'n',
|
|
79
|
+
'o',
|
|
80
|
+
'p',
|
|
81
|
+
'q',
|
|
82
|
+
'r',
|
|
83
|
+
's',
|
|
84
|
+
't',
|
|
85
|
+
'u',
|
|
86
|
+
'v',
|
|
87
|
+
'w',
|
|
88
|
+
'x',
|
|
89
|
+
'y',
|
|
90
|
+
'z',
|
|
91
|
+
0,
|
|
92
|
+
1,
|
|
93
|
+
2,
|
|
94
|
+
3,
|
|
95
|
+
4,
|
|
96
|
+
5,
|
|
97
|
+
6,
|
|
98
|
+
7,
|
|
99
|
+
8,
|
|
100
|
+
9,
|
|
101
|
+
];
|
|
66
102
|
/**
|
|
67
103
|
* Creates a random string (including letters and numbers) of a given length.
|
|
68
104
|
*
|
|
69
105
|
* This function uses cryptographically secure randomness.
|
|
70
106
|
*/
|
|
71
107
|
export function randomString(inputLength = 16) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*/
|
|
82
|
-
.substring(0, inputLength));
|
|
108
|
+
let stringBuilder = '';
|
|
109
|
+
for (let i = 0; i < inputLength; i++) {
|
|
110
|
+
const index = randomInteger({
|
|
111
|
+
min: 0,
|
|
112
|
+
max: validStringCharacters.length - 1,
|
|
113
|
+
});
|
|
114
|
+
stringBuilder += validStringCharacters[index];
|
|
115
|
+
}
|
|
116
|
+
return stringBuilder;
|
|
83
117
|
}
|
|
84
|
-
/* c8 ignore stop */
|