GithubHelp home page GithubHelp 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

port-selector's People

Contributors

renovate-bot avatar zingerlittlebee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

port-selector's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

cargo
Cargo.toml
  • napi 2.4.3
  • napi-derive 2.4.1
  • port-selector 0.1.6
  • napi-build 2.0.0
github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions-rs/toolchain v1
  • actions-rs/cargo v1
  • actions/cache v3
  • actions/cache v3
  • actions/cache v3
  • addnab/docker-run-action v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • vmactions/freebsd-vm v0.1.6
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/download-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/download-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/download-artifact v3
  • actions/checkout v3
  • actions/download-artifact v3
  • actions/cache v3
  • addnab/docker-run-action v3
  • actions/checkout v3
  • actions/download-artifact v3
  • actions/cache v3
  • addnab/docker-run-action v3
  • actions/checkout v3
  • actions/download-artifact v3
  • actions/cache v3
  • addnab/docker-run-action v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/download-artifact v3
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
npm
npm/android-arm-eabi/package.json
  • node >= 10
npm/android-arm64/package.json
  • node >= 10
npm/darwin-arm64/package.json
  • node >= 10
npm/darwin-x64/package.json
  • node >= 10
npm/freebsd-x64/package.json
  • node >= 10
npm/linux-arm-gnueabihf/package.json
  • node >= 10
npm/linux-arm64-gnu/package.json
  • node >= 10
npm/linux-arm64-musl/package.json
  • node >= 10
npm/linux-x64-gnu/package.json
  • node >= 10
npm/linux-x64-musl/package.json
  • node >= 10
npm/win32-arm64-msvc/package.json
  • node >= 10
npm/win32-ia32-msvc/package.json
  • node >= 10
npm/win32-x64-msvc/package.json
  • node >= 10
package.json
  • @napi-rs/cli 2.9.0
  • @commitlint/cli 16.3.0
  • @commitlint/config-conventional 16.2.4
  • @types/jest 28.1.1
  • @types/node 17.0.30
  • @typescript-eslint/eslint-plugin 5.27.1
  • @typescript-eslint/parser 5.27.1
  • commitizen 4.2.4
  • commitlint 16.3.0
  • eslint 8.17.0
  • eslint-config-prettier 8.5.0
  • eslint-plugin-prettier 4.0.0
  • git-cz 4.9.0
  • husky 7.0.4
  • jest 28.1.0
  • prettier 2.6.2
  • ts-jest 28.0.4
  • typescript 4.7.3
  • ts-node 10.8.1
  • node >= 10

  • Check this box to trigger a request for Renovate to run again on this repository

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.