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