X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fcommon.js;h=dc0585471303780c5720ab0d5f62fdf55d11d059;hb=cf9590ecbcd4b0a7c01f153cacade619518f84f0;hp=cfdf9db7e5c47feda5e05b52624a17a25949d853;hpb=cbc34a48ad25784a42673faa7c48067c4bfa10a2;p=squeep-indieauth-helper diff --git a/lib/common.js b/lib/common.js index cfdf9db..dc05854 100644 --- a/lib/common.js +++ b/lib/common.js @@ -64,9 +64,44 @@ const pick = (obj, props) => { }; +/** + * Return a set containing non-shared items between two sets. + * @param {Set} a + * @param {Set} b + * @returns {Set} + */ +const setSymmetricDifference = (a, b) => { + const d = new Set(a); + for (const x of b) { + if (d.has(x)) { + d.delete(x); + } else { + d.add(x); + } + } + return d; +}; + + +/** + * URL objects have weird names. + * @param {String} component + * @returns {String} + */ +const properURLComponentName = (component) => { + // eslint-disable-next-line security/detect-object-injection + return { + hash: 'fragment', + protocol: 'scheme', + }[component] || component; +} + + module.exports = { fileScope, axiosResponseLogData, logTruncate, pick, + setSymmetricDifference, + properURLComponentName, }; \ No newline at end of file