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 +1 -1
- package/package.json +1 -1
- package/ts/funcs/randomIP6.d.ts +1 -0
- package/ts/funcs/randomIP6.js +16 -0
- package/ts/funcs/randomIP6.test.js +18 -0
- package/ts/funcs/randomIP6.ts +12 -0
- package/ts/index.d.ts +1 -0
- package/ts/index.js +1 -0
- package/ts/index.ts +2 -0
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
|
@@ -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
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);
|