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

@dnslink/js

v0.13.0

Published

The reference implementation for DNSLink in JavaScript. Tested in Node.js and in the Browser.

Downloads

35

Readme

@dnslink/js

The reference implementation for DNSLink resolver in JavaScript. Tested in Node.js and in the Browser.

Usage

You can use dnslink both as a CLI tool or a library.

JavaScript API

Getting started with DNSLink resolution in a jiffy:

import { resolve, DNSRcodeError } from '@dnslink/js'

// assumes top-level await
let result
try {
  result = await resolve('dnslink.dev/abcd?foo=bar', {
    endpoints: ['dns.google'], // required! see more below.
    /* (optional) */
    signal, // AbortSignal that you can use to abort the request
    timeout: 1000, // timeout for the operation
    retries: 3 // retries in case of transport error
  })
} catch (err) {
  // Errors provided by DNS server
  if (err instanceof DNSRcodeError) {
    err.rcode // Error code number following - https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
    err.error // Error code name following (same list)
    err.code // `RCODE_${err.code}
    err.domain // Domain lookup that resulted in the error
    if (err.rcode === 3) {
      // NXDomain = Domain not found; most relevant error
    }
  } else {
    // A variety other errors may be thrown as well. Possible causes include, but are not limited to:
    // - Invalid input
    // - Timeouts / aborts
    // - Networking errors
    // - Incompatible dns packets provided by server
  }
}
const { links, log, txtEntries } = result

// `links` is an object containing given links for the different namespaces
// Each names contains an identifier and a ttl.
links.ipfs === [{ identifier: 'QmTg....yomU', ttl: 60 }]

// The `log` is always an Array and contains a list of log entries
// that were should help to trace back how the linked data was resolved.
Array.isArray(log)

// The `txtEntries` are a reduced form of the links that contains the namespace 
// as part of the value
txtEntries === [{ value: '/ipfs/QmTg....yomU', ttl: 60 }]

Endpoints

You need to specify endpoints to be used with the API. You can specify them the same way as you would in dns-query.

Possible log statements

The statements contained in the log are all objects. They may be helpful to figure out why dnslink is not behaving like you expect. Every statement contains the .code property that holds the .code property to understand what happened. Depending on the warnings code the errors may have additional .entry property that holds the problematic TXT entry. A .reason property may contain an additional reason for that error to occur.

| .code | Meaning | Additional properties | |--------------------------|-------------------------------------------------------------------------------|-----------------------| | FALLBACK | No _dnslink. prefixed domain was found. Falling back to the regular domain. | | | INVALID_ENTRY | A TXT entry with dnslink= prefix has formatting errors. | .entry, .reason |

Command Line

To use dnslink in the command line you will need Node.js installed.

Install it permanently using npm i -g @dnslink/js or run in on-the-fly using npx @dnslink/js.

You can get detailed help for the app by passing a --help option at the end:

$ npx @dnslink/js --help

License

Published under dual-license: MIT OR Apache-2.0