sip-nonce 0.2.2 → 0.2.3
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/index.js +12 -12
- package/dist/esm/index.js +12 -12
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const nonce = () => {
|
|
4
|
-
|
|
5
|
-
return result;
|
|
4
|
+
return randomString(randomInt(10, 16));
|
|
6
5
|
};
|
|
7
6
|
function randomString(length) {
|
|
8
7
|
let res = '';
|
|
9
8
|
const offset = randomInt(2, 11);
|
|
10
|
-
let charset = '
|
|
9
|
+
let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
11
10
|
var randChars = shuffleString(`${charset}${charset}${charset}`);
|
|
12
11
|
for (let i = 0; i < length + offset + 1; i++) {
|
|
13
12
|
res += randChars.charAt(Math.floor(Math.random() * randChars.length));
|
|
@@ -15,23 +14,24 @@ function randomString(length) {
|
|
|
15
14
|
return res.substring(offset, offset + length);
|
|
16
15
|
}
|
|
17
16
|
function randomInt(min, max) {
|
|
18
|
-
if (!min || min < 1)
|
|
17
|
+
if (!min || min < 1 || typeof min != "number")
|
|
19
18
|
min = 1;
|
|
20
|
-
if (!max || max > 9007199254740991)
|
|
19
|
+
if (!max || max > 9007199254740991 || typeof min != "number")
|
|
21
20
|
max = 9007199254740991;
|
|
22
21
|
min = Math.ceil(min);
|
|
23
22
|
max = Math.floor(max);
|
|
24
23
|
if (min > max)
|
|
25
|
-
return randomInt(min
|
|
26
|
-
return Math.floor(Math.random() * (max - min +
|
|
24
|
+
return randomInt(min);
|
|
25
|
+
return Math.floor(min + Math.random() * (max - min) + Math.random());
|
|
27
26
|
}
|
|
28
27
|
function shuffleString(str) {
|
|
29
28
|
let arr = Array.from(str);
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
let currIndex = arr.length;
|
|
30
|
+
let randIndex;
|
|
31
|
+
while (currIndex !== 0) {
|
|
32
|
+
randIndex = Math.floor(Math.random() * currIndex);
|
|
33
|
+
currIndex--;
|
|
34
|
+
[arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
|
|
35
35
|
}
|
|
36
36
|
return arr.join('');
|
|
37
37
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
const nonce = () => {
|
|
2
|
-
|
|
3
|
-
return result;
|
|
2
|
+
return randomString(randomInt(10, 16));
|
|
4
3
|
};
|
|
5
4
|
function randomString(length) {
|
|
6
5
|
let res = '';
|
|
7
6
|
const offset = randomInt(2, 11);
|
|
8
|
-
let charset = '
|
|
7
|
+
let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
9
8
|
var randChars = shuffleString(`${charset}${charset}${charset}`);
|
|
10
9
|
for (let i = 0; i < length + offset + 1; i++) {
|
|
11
10
|
res += randChars.charAt(Math.floor(Math.random() * randChars.length));
|
|
@@ -13,23 +12,24 @@ function randomString(length) {
|
|
|
13
12
|
return res.substring(offset, offset + length);
|
|
14
13
|
}
|
|
15
14
|
function randomInt(min, max) {
|
|
16
|
-
if (!min || min < 1)
|
|
15
|
+
if (!min || min < 1 || typeof min != "number")
|
|
17
16
|
min = 1;
|
|
18
|
-
if (!max || max > 9007199254740991)
|
|
17
|
+
if (!max || max > 9007199254740991 || typeof min != "number")
|
|
19
18
|
max = 9007199254740991;
|
|
20
19
|
min = Math.ceil(min);
|
|
21
20
|
max = Math.floor(max);
|
|
22
21
|
if (min > max)
|
|
23
|
-
return randomInt(min
|
|
24
|
-
return Math.floor(Math.random() * (max - min +
|
|
22
|
+
return randomInt(min);
|
|
23
|
+
return Math.floor(min + Math.random() * (max - min) + Math.random());
|
|
25
24
|
}
|
|
26
25
|
function shuffleString(str) {
|
|
27
26
|
let arr = Array.from(str);
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
let currIndex = arr.length;
|
|
28
|
+
let randIndex;
|
|
29
|
+
while (currIndex !== 0) {
|
|
30
|
+
randIndex = Math.floor(Math.random() * currIndex);
|
|
31
|
+
currIndex--;
|
|
32
|
+
[arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
|
|
33
33
|
}
|
|
34
34
|
return arr.join('');
|
|
35
35
|
}
|