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

ssb-msgs

v5.2.0

Published

message-processing tools for secure-scuttlebutt

Downloads

372

Readme

SSB Messages

Message-processing tools for secure-scuttlebutt

var mlib = require('ssb-msgs')

indexLinks

indexLinks(msg: Object, [opts: Options], each: Function(link: Object, rel: String))
where Options = { rel: String, msg: Bool/String, feed: Bool/String, ext: Bool/String }

Traverses a message and runs the each function on all found links. All opts fields are optional. Opts may also be a string, in which case it is the rel attribute

// assume %msgid and @feedid a well-formed
var msg = {
  foo: { link: '%msgid' },
  bar: [{ link: '@feedid' }]
}
function print (obj, rel) {
  console.log(rel, obj.link)  
}
mlib.indexLinks(msg, print)
// => foo %msgid
// => bar @feedid
mlib.indexLinks(msg, 'foo', print)
// => foo %msgid
mlib.indexLinks(msg, { rel: 'foo' }, print)
// => foo %msgid
mlib.indexLinks(msg, { feed: true }, print)
// => bar @feedid
mlib.indexLinks(msg, { feed: '@feedid' }, print)
// => bar @feedid

links (or asLinks)

links(obj: Any, [requiredAttr: String])

Helper to get links from a message in a regular array form.

var msg = {
  foo: { link: '%msgid' },
  bar: [{ link: '@feedid' }]
}
mlib.links(msg.foo) // => [{ link: '%msgid' }]
mlib.links(msg.bar) // => [{ link: '@feedid' }]
mlib.links(msg.bar, 'feed') // => [{ link: '@feedid' }]
mlib.links(msg.bar, 'msg') // => []
mlib.links(msg.baz) // => []

link (or asLink)

link(obj: Any, [requiredAttr: String])

Helper to get a link from a message in a regular object form. If an array is found, will use the first element.

var msg = {
  foo: { link: '%msgid' },
  bar: [{ link: '@feedid' }]
}
mlib.link(msg.foo) // => { link: '%msgid' }
mlib.link(msg.bar) // => { link: '@feedid' }
mlib.link(msg.bar, 'feed') // => { link: '@feedid' }
mlib.link(msg.bar, 'msg') // => null
mlib.link(msg.baz) // => null

isLink

isLink(obj: Any, [requiredAttr: String])

Predicate to test whether an object is a well-formed link. Returns false if given an array.

var msg = {
  foo: { link: '%msgid' },
  bar: [{ link: '@feedid' }]
}
mlib.isLink(msg.foo) // => true
mlib.isLink(msg.bar) // => true
mlib.isLink(msg.bar, 'feed') // => true
mlib.isLink(msg.bar, 'msg') // => false
mlib.isLink(msg.baz) // => false

linksTo

linksTo(a: Message, b: Message)

Get link objects pointing from a to b.

mlib.linksTo(msgA, msgB) // => [{ link: '%msgB-id' }]

relationsTo

relationsTo(a: Message, b: Message)

Get relations of links pointing from a to b.

mlib.relationsTo(msgA, msgB) // => ['fooRelation']