diff options
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index d6c3133..fe7a335 100644 --- a/lib/util.js +++ b/lib/util.js @@ -78,3 +78,20 @@ u.renderError = function(err) { h('h3', err.name), h('pre', err.stack)) } + +u.pullLength = function (cb) { + var len = 0 + return pull.through(function (data) { + len += data.length + }, function (err) { + cb(err, len) + }) +} + +u.tryDecodeJSON = function (json) { + try { + return JSON.parse(json) + } catch(e) { + return null + } +} |