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

simple-hosts

v1.2.3

Published

Simple functions to manipulate hosts file contents

Downloads

106

Readme

simple-hosts

Easy way to manipulate the hosts file contents.

Why this?

  • simple, lightweight
  • synchronous =>
    • less error prone over other library since they open the small file for very long time which may cause file corruption
    • ease of use, don't need to chain with Promise
  • support multiple hostname associated with a single IP address
  • well tested before release
  • transparent source code
  • free of use

What's news?

  • 1.1.0
    • Improve set() function to support new separate entry
  • 1.2.0
    • Fix the set() function to support modifying existed hostname
  • 1.2.1
    • Refactor the source code. Create SimpleHosts class supporting input hosts file path
    • Add test cases
    • Update document
  • 1.2.2
    • Use typescript
  • 1.2.3
    • Support remove records by IP or hostname with removeIp() and removeHost() function

This package provides the below synchronous functions

  1. Get corresponding IP of a hostname

    getIp(hostname: string): string

    Returns the corresponding IP that is mapped to the input hostname. If no record is found, it will return an empty string. If there are multiple IPs that are mapped to a same hostname, the first IP will be returned. Multiple IPs for a same hostname is not encouraged because it causes ambiguous

  2. Get corresponding hostnames of an IP

    getHosts(ip: string): string[]

    Returns an array of found hostnames that are mapped to the input IP

  3. Create or modify a record in hosts file

    set(ip: string, hostname: string): void

    If the same record that contains same IP and same hostname has been in the hosts file, no additional writing is performed. If the hostname has been already existed, it will be removed from the map of current IP and then new record will be added.

  4. Remove records by ID address

    removeIp(ip: string): void
  5. Remove records by hostname

    removeHost(hostname: string): void