sip-nonce 0.2.4 → 0.2.8
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 +11 -11
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +11 -11
- package/package.json +43 -43
package/dist/cjs/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const nonce = (minLength =
|
|
4
|
-
if (typeof minLength !=
|
|
3
|
+
const nonce = function (minLength = 10, maxLength = 16) {
|
|
4
|
+
if (typeof minLength != "number" || minLength < 8)
|
|
5
5
|
minLength = 8;
|
|
6
|
-
if (typeof maxLength !=
|
|
6
|
+
if (typeof maxLength != "number" || maxLength > 24)
|
|
7
7
|
maxLength = 24;
|
|
8
8
|
const length = randomInt(minLength, maxLength);
|
|
9
|
-
const offset = randomInt(
|
|
10
|
-
let chars =
|
|
11
|
-
chars = shuffleString(chars.repeat(
|
|
12
|
-
let res =
|
|
9
|
+
const offset = randomInt(0, maxLength);
|
|
10
|
+
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
11
|
+
chars = shuffleString(chars.repeat(3));
|
|
12
|
+
let res = "";
|
|
13
13
|
for (let i = 0; i < length + offset + 1; i++) {
|
|
14
14
|
res += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
15
15
|
}
|
|
@@ -18,8 +18,8 @@ const nonce = (minLength = 8, maxLength = 10) => {
|
|
|
18
18
|
function randomInt(min, max) {
|
|
19
19
|
if (!min || min < 1 || typeof min != "number")
|
|
20
20
|
min = 1;
|
|
21
|
-
if (!max || max >
|
|
22
|
-
max =
|
|
21
|
+
if (!max || max > 24 || typeof min != "number")
|
|
22
|
+
max = 24;
|
|
23
23
|
min = Math.ceil(min);
|
|
24
24
|
max = Math.floor(max);
|
|
25
25
|
if (min > max)
|
|
@@ -35,6 +35,6 @@ function shuffleString(str) {
|
|
|
35
35
|
currIndex--;
|
|
36
36
|
[arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
|
|
37
37
|
}
|
|
38
|
-
return arr.join(
|
|
38
|
+
return arr.join("");
|
|
39
39
|
}
|
|
40
|
-
exports.default =
|
|
40
|
+
exports.default = nonce;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const nonce: (minLength?: number, maxLength?: number) => string;
|
|
2
|
+
export default nonce;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const nonce = (minLength =
|
|
2
|
-
if (typeof minLength !=
|
|
1
|
+
const nonce = function (minLength = 10, maxLength = 16) {
|
|
2
|
+
if (typeof minLength != "number" || minLength < 8)
|
|
3
3
|
minLength = 8;
|
|
4
|
-
if (typeof maxLength !=
|
|
4
|
+
if (typeof maxLength != "number" || maxLength > 24)
|
|
5
5
|
maxLength = 24;
|
|
6
6
|
const length = randomInt(minLength, maxLength);
|
|
7
|
-
const offset = randomInt(
|
|
8
|
-
let chars =
|
|
9
|
-
chars = shuffleString(chars.repeat(
|
|
10
|
-
let res =
|
|
7
|
+
const offset = randomInt(0, maxLength);
|
|
8
|
+
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
9
|
+
chars = shuffleString(chars.repeat(3));
|
|
10
|
+
let res = "";
|
|
11
11
|
for (let i = 0; i < length + offset + 1; i++) {
|
|
12
12
|
res += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
13
13
|
}
|
|
@@ -16,8 +16,8 @@ const nonce = (minLength = 8, maxLength = 10) => {
|
|
|
16
16
|
function randomInt(min, max) {
|
|
17
17
|
if (!min || min < 1 || typeof min != "number")
|
|
18
18
|
min = 1;
|
|
19
|
-
if (!max || max >
|
|
20
|
-
max =
|
|
19
|
+
if (!max || max > 24 || typeof min != "number")
|
|
20
|
+
max = 24;
|
|
21
21
|
min = Math.ceil(min);
|
|
22
22
|
max = Math.floor(max);
|
|
23
23
|
if (min > max)
|
|
@@ -33,6 +33,6 @@ function shuffleString(str) {
|
|
|
33
33
|
currIndex--;
|
|
34
34
|
[arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
|
|
35
35
|
}
|
|
36
|
-
return arr.join(
|
|
36
|
+
return arr.join("");
|
|
37
37
|
}
|
|
38
|
-
export default
|
|
38
|
+
export default nonce;
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
"name": "sip-nonce",
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"description": "Small library for generating random nonce values for SIP challenges",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sip-nonce",
|
|
7
|
+
"sip",
|
|
8
|
+
"nonce"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/phonecloud-com/sip-nonce#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/phonecloud-com/sip-nonce/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/phonecloud-com/sip-nonce.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"author": "PhoneCloud",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"types": "./dist/esm/index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build:esm": "tsc",
|
|
24
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
25
|
+
"build": "rm -rf dist/* && npm run build:esm && npm run build:cjs"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/esm/index.d.ts",
|
|
30
|
+
"import": "./dist/esm/index.js",
|
|
31
|
+
"require": "./dist/cjs/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"prettier": "^3.7.4",
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
}
|
|
45
45
|
}
|