sip-nonce 0.2.0 → 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.
@@ -1,37 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const nonce = () => {
4
- let result = randomString(randomInt(10, 16));
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 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12345679';
11
- var randChars = shuffleString(charset + charset + charset);
9
+ let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
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));
14
13
  }
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, min);
26
- return Math.floor(Math.random() * (max - min + 1)) + 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 currentIndex = arr.length, randIndex;
31
- while (currentIndex !== 0) {
32
- randIndex = Math.floor(Math.random() * currentIndex);
33
- currentIndex--;
34
- [arr[currentIndex], arr[randIndex]] = [arr[randIndex], arr[currentIndex]];
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
  }
@@ -1,35 +1,35 @@
1
1
  const nonce = () => {
2
- let result = randomString(randomInt(10, 16));
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 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12345679';
9
- var randChars = shuffleString(charset + charset + charset);
7
+ let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
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));
12
11
  }
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, min);
24
- return Math.floor(Math.random() * (max - min + 1)) + 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 currentIndex = arr.length, randIndex;
29
- while (currentIndex !== 0) {
30
- randIndex = Math.floor(Math.random() * currentIndex);
31
- currentIndex--;
32
- [arr[currentIndex], arr[randIndex]] = [arr[randIndex], arr[currentIndex]];
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-nonce",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "description": "Small library for generating random SIP nonce values",
5
5
  "keywords": [
6
6
  "sip-nonce",
@@ -16,12 +16,12 @@
16
16
  "url": "git+https://github.com/phonecloud-com/sip-nonce.git"
17
17
  },
18
18
  "license": "ISC",
19
- "author": "Matt MacAdams",
19
+ "author": "PhoneCloud",
20
20
  "type": "module",
21
- "types": "./dist/index.d.ts",
21
+ "types": "./dist/esm/index.d.ts",
22
22
  "scripts": {
23
23
  "build:esm": "tsc",
24
- "build:cjs": "tsc -p tsconfig.cjs.json && mv dist-cjs/index.js dist/index.cjs; rm -fr dist-cjs/",
24
+ "build:cjs": "tsc -p tsconfig.cjs.json",
25
25
  "build": "rm -rf dist && npm run build:esm && npm run build:cjs"
26
26
  },
27
27
  "exports": {
File without changes