Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rjweb/utils

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rjweb/utils - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## 1.1.1
- Make `network.test` return ms if success
- Make `network.isIP` return the ip type if success
## 1.1.0

@@ -2,0 +7,0 @@

17

lib/cjs/network.js

@@ -38,5 +38,6 @@ "use strict";

return new Promise((resolve) => {
const start = performance.now();
const timer = setTimeout(() => {
connection.end();
resolve(false);
connection.destroy();
}, timeout);

@@ -49,13 +50,13 @@ const connection = net.createConnection({

connection.once("connect", () => {
resolve(true);
connection.end();
resolve(performance.now() - start);
clearTimeout(timer);
}).once("error", () => {
connection.end();
}).once("error", () => {
resolve(false);
clearTimeout(timer);
}).once("timeout", () => {
connection.end();
}).once("timeout", () => {
resolve(false);
clearTimeout(timer);
connection.end();
});

@@ -69,7 +70,7 @@ });

if (type === "v6 | v4")
return true;
return `v${is}`;
if (type === "v4" && is === 4)
return true;
return "v4";
if (type === "v6" && is === 6)
return true;
return "v6";
return false;

@@ -76,0 +77,0 @@ }

{
"name": "@rjweb/utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

import * as net from "net";
function test(host, port, timeout = 1e4) {
return new Promise((resolve) => {
const start = performance.now();
const timer = setTimeout(() => {
connection.end();
resolve(false);
connection.destroy();
}, timeout);

@@ -14,13 +15,13 @@ const connection = net.createConnection({

connection.once("connect", () => {
resolve(true);
connection.end();
resolve(performance.now() - start);
clearTimeout(timer);
}).once("error", () => {
connection.end();
}).once("error", () => {
resolve(false);
clearTimeout(timer);
}).once("timeout", () => {
connection.end();
}).once("timeout", () => {
resolve(false);
clearTimeout(timer);
connection.end();
});

@@ -34,7 +35,7 @@ });

if (type === "v6 | v4")
return true;
return `v${is}`;
if (type === "v4" && is === 4)
return true;
return "v4";
if (type === "v6" && is === 6)
return true;
return "v6";
return false;

@@ -41,0 +42,0 @@ }

{
"name": "@rjweb/utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

/**
* Check the Connection to a Host + Port
* Check the Connection (Time) to a Host + Port
* @default

@@ -8,6 +8,7 @@ * ```

* // host, port, timeout ms
* await network.test('127.0.0.1', 80, 5000) // true
* await network.test('127.0.0.1', 80, 5000) // 7.270833998918533
* ```
* @returns ms it took to connect or false if failed
* @since 1.1.0
*/ export declare function test(host: string, port: number, timeout?: number): Promise<boolean>;
*/ export declare function test(host: string, port: number, timeout?: number): Promise<number | false>;
/**

@@ -19,9 +20,10 @@ * Check if an IP is valid

*
* network.isIP('127.0.0.1', 'v4') // true
* network.isIP('127.0.0.1', 'v4') // 'v4'
* network.isIP('127.0.0.1', 'v6') // false
* network.isIP('::1', 'v4') // false
* network.isIP('::1, 'v6') // true
* network.isIP('127.0.0.1', 'v6 | v4') // true
* network.isIP('::1', 'v6') // 'v6'
* network.isIP('127.0.0.1', 'v6 | v4') // 'v4'
* ```
* @returns IP Type or false if failed
* @since 1.1.0
*/ export declare function isIP(ip: string, type?: 'v4' | 'v6' | 'v6 | v4'): boolean;
*/ export declare function isIP(ip: string, type?: 'v4' | 'v6' | 'v6 | v4'): 'v4' | 'v6' | false;
{
"name": "@rjweb/utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "module": "lib/esm/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc