diff options
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/util.js b/lib/util.js index d25ecaf..e4cf415 100644 --- a/lib/util.js +++ b/lib/util.js @@ -72,13 +72,17 @@ u.linkDest = function (link) { } u.toArray = function (x) { - return !x ? [] : Array.isArray(x) ? x : [x] + return x == null ? [] : Array.isArray(x) ? x : [x] } u.fromArray = function (arr) { return Array.isArray(arr) && arr.length === 1 ? arr[0] : arr } +u.toLinkArray = function (x) { + return u.toArray(x).map(u.toLink).filter(u.linkDest) +} + u.renderError = function(err) { return h('div.error', h('h3', err.name), @@ -102,7 +106,7 @@ u.tryDecodeJSON = function (json) { } } -u.extractFeedIds = function (str) { +u.extractRefs = function (str) { var ids = [] String(str).replace(u.ssbRefRegex, function (id) { ids.push(id) @@ -110,6 +114,18 @@ u.extractFeedIds = function (str) { return ids } +u.extractFeedIds = function (str) { + return u.extractRefs(str).filter(function (ref) { + return ref[0] === '@' + }) +} + +u.extractBlobIds = function (str) { + return u.extractRefs(str).filter(function (ref) { + return ref[0] === '&' + }) +} + u.isMsgReadable = function (msg) { var c = msg && msg.value && msg.value.content return typeof c === 'object' && c !== null @@ -137,6 +153,7 @@ u.customError = function (name) { } u.escapeHTML = function (html) { + if (!html) return '' return html.toString('utf8') .replace(/</g, '<') .replace(/>/g, '>') |