npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

port-selector

v0.1.5

Published

a cross-platform Node library written in TypeScript and implemented in Rust. It mainly provides port availability checking and filtering ports based on filter conditions.

Downloads

9

Readme

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

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.

Install

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 += starterPort 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