git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 2231341bc0bba5fa0121c041ed4184a9d81992d7

Files: 2231341bc0bba5fa0121c041ed4184a9d81992d7 / router / sync / normalise.js

750 bytesRaw
1const nest = require('depnest')
2const { isBlob, isFeed, isMsg } = require('ssb-ref')
3
4exports.gives = nest('router.sync.normalise')
5
6exports.create = (api) => nest('router.sync.normalise', normalise)
7
8function 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
18function isChannel (str) {
19 return typeof str === 'string' && str[0] === '#' && str.length > 1
20}
21
22function isPage (str) {
23 return typeof str === 'string' && str[0] === '/' && str.length > 1
24}
25

Built with git-ssb-web