X-Git-Url: http://git.squeep.com/?p=squeep-indieauth-helper;a=blobdiff_plain;f=lib%2Fcommon.js;h=67cb668a751a1c9ac9aaf693880521fbcc26ffc8;hp=789aa65ce2b55db08f177e9c255171c2f0ddaa27;hb=HEAD;hpb=004d338e7c2e4003de6c0baa2552c27221e2be39 diff --git a/lib/common.js b/lib/common.js index 789aa65..6ede0a8 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,9 +1,18 @@ 'use strict'; +/** + * @typedef {object} GotResponse + * @property {Buffer|string} body response body + * @property {Array} redirectUrls followed redirect urls + * @property {number=} retryCount retries + * @property {object=} timings timings object + * @property {object=} timings.phases timing phases object + * @property {number=} timings.phases.total timing total ms + */ /** * Pick out useful got response fields. - * @param {GotResponse} res - * @returns {Object} + * @param {GotResponse} res response + * @returns {object} filtered response */ const gotResponseLogData = (res) => { const data = pick(res, [ @@ -32,9 +41,9 @@ const gotResponseLogData = (res) => { /** * Limit length of string to keep logs sane - * @param {String} str - * @param {Number} len - * @returns {String} + * @param {string} str string + * @param {number} len length + * @returns {string} truncated string */ const logTruncate = (str, len) => { if (typeof str !== 'string' || str.toString().length <= len) { @@ -46,8 +55,9 @@ const logTruncate = (str, len) => { /** * Return a new object with selected props. - * @param {Object} obj - * @param {String[]} props + * @param {object} obj object + * @param {string[]} props list of properties + * @returns {object} filtered object */ const pick = (obj, props) => { return props.reduce((acc, prop) => { @@ -61,9 +71,9 @@ const pick = (obj, props) => { /** * Return a set containing non-shared items between two sets. - * @param {Set} a - * @param {Set} b - * @returns {Set} + * @param {Set} a set a + * @param {Set} b set b + * @returns {Set} set difference */ const setSymmetricDifference = (a, b) => { const d = new Set(a); @@ -80,8 +90,8 @@ const setSymmetricDifference = (a, b) => { /** * URL objects have weird names. - * @param {String} component - * @returns {String} + * @param {string} component url component name + * @returns {string} translated url component name */ const properURLComponentName = (component) => { // eslint-disable-next-line security/detect-object-injection @@ -89,7 +99,7 @@ const properURLComponentName = (component) => { hash: 'fragment', protocol: 'scheme', }[component] || component; -} +}; module.exports = {