sip-nonce 0.2.3 → 0.2.6

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 CHANGED
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const nonce = () => {
4
- return randomString(randomInt(10, 16));
5
- };
6
- function randomString(length) {
7
- let res = '';
8
- const offset = randomInt(2, 11);
9
- let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10
- var randChars = shuffleString(`${charset}${charset}${charset}`);
3
+ const nonce = function (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(4));
12
+ let res = "";
11
13
  for (let i = 0; i < length + offset + 1; i++) {
12
- res += randChars.charAt(Math.floor(Math.random() * randChars.length));
14
+ res += chars.charAt(Math.floor(Math.random() * chars.length));
13
15
  }
14
16
  return res.substring(offset, offset + length);
15
- }
17
+ };
16
18
  function randomInt(min, max) {
17
19
  if (!min || min < 1 || typeof min != "number")
18
20
  min = 1;
19
- if (!max || max > 9007199254740991 || typeof min != "number")
20
- max = 9007199254740991;
21
+ if (!max || max > 24 || typeof min != "number")
22
+ max = 24;
21
23
  min = Math.ceil(min);
22
24
  max = Math.floor(max);
23
25
  if (min > max)
@@ -33,6 +35,6 @@ function shuffleString(str) {
33
35
  currIndex--;
34
36
  [arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
35
37
  }
36
- return arr.join('');
38
+ return arr.join("");
37
39
  }
38
- exports.default = (nonce);
40
+ exports.default = nonce;
@@ -1,2 +1,2 @@
1
- declare const _default: () => string;
2
- export default _default;
1
+ declare const nonce: (minLength?: number, maxLength?: number) => string;
2
+ export default nonce;
package/dist/esm/index.js CHANGED
@@ -1,21 +1,23 @@
1
- const nonce = () => {
2
- return randomString(randomInt(10, 16));
3
- };
4
- function randomString(length) {
5
- let res = '';
6
- const offset = randomInt(2, 11);
7
- let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
8
- var randChars = shuffleString(`${charset}${charset}${charset}`);
1
+ const nonce = function (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(4));
10
+ let res = "";
9
11
  for (let i = 0; i < length + offset + 1; i++) {
10
- res += randChars.charAt(Math.floor(Math.random() * randChars.length));
12
+ res += chars.charAt(Math.floor(Math.random() * chars.length));
11
13
  }
12
14
  return res.substring(offset, offset + length);
13
- }
15
+ };
14
16
  function randomInt(min, max) {
15
17
  if (!min || min < 1 || typeof min != "number")
16
18
  min = 1;
17
- if (!max || max > 9007199254740991 || typeof min != "number")
18
- max = 9007199254740991;
19
+ if (!max || max > 24 || typeof min != "number")
20
+ max = 24;
19
21
  min = Math.ceil(min);
20
22
  max = Math.floor(max);
21
23
  if (min > max)
@@ -31,6 +33,6 @@ function shuffleString(str) {
31
33
  currIndex--;
32
34
  [arr[currIndex], arr[randIndex]] = [arr[randIndex], arr[currIndex]];
33
35
  }
34
- return arr.join('');
36
+ return arr.join("");
35
37
  }
36
- export default (nonce);
38
+ export default nonce;
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
1
  {
2
- "name": "sip-nonce",
3
- "version": "0.2.3",
4
- "description": "Small library for generating random SIP nonce values",
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
- "@types/node": "^20.19.27",
42
- "ts-node": "^10.9.2",
43
- "typescript": "^5.9.3"
44
- }
2
+ "name": "sip-nonce",
3
+ "version": "0.2.6",
4
+ "description": "Small library for generating random SIP nonce values",
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
  }