Giter Site home page Giter Site logo

zingerlittlebee / port-selector Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 549 KB

select port what you want for NodeJS power by Rust

Home Page: https://npmjs.com/package/port-selector

License: MIT License

JavaScript 67.61% Shell 0.95% TypeScript 12.58% Rust 18.86%
nodejs nodejs-library port rust

port-selector's Introduction

Language : 🇺🇸 English | 🇨🇳 简体中文

port-selector

NPM Version NPM Downloads Bundle Size

GitHub Actions CI License

Overview

port-selector is a cross-platform NodeJS library implemented in Rust. It mainly provides port availability checking and filtering ports based on filter conditions.

Getting Started

Prerequisites

  • Node.js (>= 10.0.0 required, LTS preferred)

Installation

npm install port-selector
# or
yarn add port-selector
# or
pnpm i port-selector
import {
    Selector,
    isFree,
    isFreeTcp,
    isFreeUdp,
    randomFreePort,
    randomFreeTcpPort,
    randomFreeUdpPort,
    selectFreePort,
    selectFromGivenPort
} from 'port-selector'

Goods

isFree · isFreeTcp · isFreeUdp · randomFreePort · randomFreeTcpPort · randomFreeUdpPort · selectFromGivenPort · selectFreePort

Documentation

isFree

Check whether the port is not used on TCP and UDP

function isFree(port: number): boolean

isFreeTcp

Check whether the port is not used on TCP

function isFreeTcp(port: number): boolean

isFreeUdp

Check whether the port is not used on UDP

function isFreeUdp(port: number): boolean

randomFreePort

The system randomly assigns available TCP and UDP ports

function randomFreePort(): number

randomFreeTcpPort

The system randomly assigns available TCP ports

function randomFreeTcpPort(): number

randomFreeUdpPort

The system randomly assigns available UDP ports

function randomFreeUdpPort(): number

selectFromGivenPort

Check from starterPort and return the first available port

Return if starterPort is available; Otherwise starterPort += 1 until the port is available

function selectFromGivenPort(starterPort: number): number

selectFreePort

Gets a matching port based on the Selector parameter constraint

function selectFreePort(selector?: Selector): number
export type Selector = {
    // Check whether the port is available on TCP.
    // The default value is true.
    checkTcp?: boolean
    // Check whether the port is available on UDP.
    // The default value is true.
    checkUdp?: boolean
    // Set the generated port range, starting value
    // The default value is 0.
    portFrom?: number
    // Set the generated port range, end value
    // The default value is 65535.
    portTo?: number
    // Maximum number of random times. Default value: 100
    // If no available port number is found within the maximum random number of loops, None is returned
    maxRandomTimes?: number
}

Thanks

napi-rs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.