csp-toolkit
Version:
A comprehensive toolkit for working with Content Security Policy (CSP) directives in TypeScript.
3 lines (2 loc) • 524 B
JavaScript
const t=(t,r,n)=>{const e=r&&Object.keys(r).length>0;if(n)return r;if(!e)return t;const s={...t};for(const n in r){const e=n;if(r.hasOwnProperty(n)){const n=t[e]||[],o=r[e]||[];Array.isArray(o)?s[e]=Array.from(new Set([...n,...o])):s[e]=o}}return s},r=t=>Object.keys(t).reduce(((r,n)=>{const e=t[n];if(!e?.length)return r;return`${r} ${n} ${e.map((t=>t.startsWith("sha")||t.startsWith("nonce")?`'${t}'`:t)).join(" ")};`}),"").trimStart();export{t as mergePolicies,r as policyToString};
//# sourceMappingURL=index.esm.js.map