Files: df012d307724d819387795ac0bdc0ed460d80be3 / router / sync / normalise.js
750 bytesRaw
1 | const nest = require('depnest') |
2 | const { isBlob, isFeed, isMsg } = require('ssb-ref') |
3 | |
4 | exports.gives = nest('router.sync.normalise') |
5 | |
6 | exports.create = (api) => nest('router.sync.normalise', normalise) |
7 | |
8 | function normalise (location) { |
9 | if (typeof location === 'object') return location |
10 | |
11 | if (isBlob(location)) return { blob: location } |
12 | if (isChannel(location)) return { channel: location } |
13 | if (isFeed(location)) return { feed: location } |
14 | if (isMsg(location)) return { key: location } |
15 | if (isPage(location)) return { page: location.substring(1) } |
16 | } |
17 | |
18 | function isChannel (str) { |
19 | return typeof str === 'string' && str[0] === '#' && str.length > 1 |
20 | } |
21 | |
22 | function isPage (str) { |
23 | return typeof str === 'string' && str[0] === '/' && str.length > 1 |
24 | } |
25 |
Built with git-ssb-web