# ssb-msgs

> message-processing tools for secure-scuttlebutt

Latest version **5.2.0** (published 2015-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install ssb-msgs
pnpm add ssb-msgs
yarn add ssb-msgs
bun add ssb-msgs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.0 |
| Published | 2015-11-28 |
| First published | 2014-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Paul Frazee |
| Maintainers | pfraze, dominictarr |

## Links

- npm: https://www.npmjs.com/package/ssb-msgs
- Repository: https://github.com/ssbc/ssb-msgs
- Issues: https://github.com/ssbc/ssb-msgs/issues
- npm.io page: https://npm.io/package/ssb-msgs

## Dependencies (1)

- [ssb-ref](https://npm.io/package/ssb-ref.md) ^2.0.0

## Recent versions

- 5.2.0 (latest) — 2015-11-28
- 5.1.0 — 2015-10-06
- 5.0.0 — 2015-07-30
- 4.0.0 — 2015-07-06
- 3.1.2 — 2015-06-29
- 3.1.1 — 2015-03-12
- 3.1.0 — 2015-03-12
- 3.0.0 — 2015-03-01
- 2.0.0 — 2015-01-13
- 1.1.1 — 2015-01-13
- 1.1.0 — 2015-01-13
- 1.0.0 — 2014-12-06
- 0.2.0 — 2014-11-11
- 0.1.1 — 2014-11-09
- 0.1.0 — 2014-11-09

## README

# SSB Messages

Message-processing tools for secure-scuttlebutt

```js
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

```js
// 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.

```js
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.

```js
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.

```js
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`.

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

### relationsTo

```
relationsTo(a: Message, b: Message)
```

Get relations of links pointing from `a` to `b`.

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

---
_Source: https://npm.io/package/ssb-msgs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
