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

dns-txt

v2.0.2

Published

Encode/decode DNS-SD TXT record RDATA fields

Downloads

13,369,093

Readme

dns-txt

Encode or decode the RDATA field in multicast DNS TXT records. For use with DNS-Based Service Discovery. For details see RFC 6763.

Build status js-standard-style abstract-encoding

Installation

npm install dns-txt

Usage

var txt = require('dns-txt')()

var obj = {
  foo: 1,
  bar: 2
}

var enc = txt.encode(obj) // <Buffer 05 66 6f 6f 3d 31 05 62 61 72 3d 32>

txt.decode(enc) // { foo: '1', bar: '2' }

API

The encoder and decoder conforms to RFC 6763.

Initialize

The module exposes a constructor function which can be called with an optional options object:

var txt = require('dns-txt')({ binary: true })

The options are:

  • binary - If set to true all values will be returned as Buffer objects. The default behavior is to turn all values into strings. But according to the RFC the values can be any binary data. If you expect binary data, use this option.

txt.encode(obj, [buffer], [offset])

Takes a key/value object and returns a buffer with the encoded TXT record. If a buffer is passed as the second argument the object should be encoded into that buffer. Otherwise a new buffer should be allocated If an offset is passed as the third argument the object should be encoded at that byte offset. The byte offset defaults to 0.

This module does not actively validate the key/value pairs, but keep the following in rules in mind:

  • To be RFC compliant, each key should conform with the rules as specified in section 6.4.

  • To be RFC compliant, each value should conform with the rules as specified in section 6.5.

After encoding txt.encode.bytes is set to the amount of bytes used to encode the object.

txt.decode(buffer, [offset], [length])

Takes a buffer and returns a decoded key/value object. If an offset is passed as the second argument the object should be decoded from that byte offset. The byte offset defaults to 0. Note that all keys will be lowercased and all values will be Buffer objects.

After decoding txt.decode.bytes is set to the amount of bytes used to decode the object.

txt.encodingLength(obj)

Takes a single key/value object and returns the number of bytes that the given object would require if encoded.

License

MIT