sip-nonce 0.2.3 → 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 CHANGED
@@ -1,18 +1,20 @@
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) {
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));
7
12
  let res = '';
8
- const offset = randomInt(2, 11);
9
- let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
10
- var randChars = shuffleString(`${charset}${charset}${charset}`);
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;
@@ -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,16 +1,18 @@
1
- const nonce = () => {
2
- return randomString(randomInt(10, 16));
3
- };
4
- function randomString(length) {
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));
5
10
  let res = '';
6
- const offset = randomInt(2, 11);
7
- let charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
8
- var randChars = shuffleString(`${charset}${charset}${charset}`);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-nonce",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Small library for generating random SIP nonce values",
5
5
  "keywords": [
6
6
  "sip-nonce",