mybase 1.1.8 → 1.1.9

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/mybase.js CHANGED
@@ -153,7 +153,7 @@ function validIpNative(str) {
153
153
  // return regex.test(str);
154
154
  }
155
155
 
156
- function randomIP() {
156
+ function randomIP() { // ported
157
157
  function int2ip (ipInt) {
158
158
  return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) );
159
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {
@@ -0,0 +1 @@
1
+ export declare function randomIP6(): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.randomIP6 = void 0;
7
+ const crypto_1 = require("crypto");
8
+ // const ip6 = require('ip6')
9
+ //@ts-ignore
10
+ const ip6_1 = __importDefault(require("ip6"));
11
+ function randomIP6() {
12
+ var _a;
13
+ const bytes = (0, crypto_1.randomBytes)(16);
14
+ return ip6_1.default.normalize(((_a = bytes.toString('hex').match(/.{1,4}/g)) === null || _a === void 0 ? void 0 : _a.join(':')) || '0000:0000:0000:0000:0000:0000:0000:0000');
15
+ }
16
+ exports.randomIP6 = randomIP6;
@@ -0,0 +1,18 @@
1
+ const ip6 = require('ip6');
2
+ const { randomIP6 } = require('./randomIP6');
3
+
4
+ describe('randomIP6', () => {
5
+ it('should generate a random IPv6 address', () => {
6
+ const result = randomIP6();
7
+ expect(()=>ip6.normalize(result)).not.toThrow()
8
+ expect(()=>ip6.abbreviate(result)).not.toThrow()
9
+ });
10
+
11
+ it('generate 100 ipv6', () => {
12
+ for (let i = 0; i < 100; i++) {
13
+ const result = randomIP6();
14
+ expect(()=>ip6.normalize(result)).not.toThrow()
15
+ expect(()=>ip6.abbreviate(result)).not.toThrow()
16
+ }
17
+ })
18
+ });
@@ -0,0 +1,12 @@
1
+ import { randomBytes } from "crypto"
2
+ // const ip6 = require('ip6')
3
+ //@ts-ignore
4
+ import ip6 from 'ip6'
5
+
6
+ export function randomIP6() : string {
7
+ const bytes = randomBytes(16)
8
+ return ip6.normalize(bytes.toString('hex').match(/.{1,4}/g)?.join(':') || '0000:0000:0000:0000:0000:0000:0000:0000')
9
+ }
10
+
11
+
12
+
package/ts/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from "./funcs/promiseTimeout";
13
13
  export * from "./funcs/randomIP";
14
14
  export * from "./funcs/ip2int";
15
15
  export * from "./funcs/int2ip";
16
+ export * from "./funcs/randomIP6";
package/ts/index.js CHANGED
@@ -29,3 +29,4 @@ __exportStar(require("./funcs/promiseTimeout"), exports);
29
29
  __exportStar(require("./funcs/randomIP"), exports);
30
30
  __exportStar(require("./funcs/ip2int"), exports);
31
31
  __exportStar(require("./funcs/int2ip"), exports);
32
+ __exportStar(require("./funcs/randomIP6"), exports);
package/ts/index.ts CHANGED
@@ -13,3 +13,5 @@ export * from "./funcs/promiseTimeout"
13
13
  export * from "./funcs/randomIP"
14
14
  export * from "./funcs/ip2int"
15
15
  export * from "./funcs/int2ip"
16
+ export * from "./funcs/randomIP6"
17
+