Set isSubsetOf and isDisjointFrom Check Policy
Verify required scopes and mutual-exclusion rules cleanly with ES2025 Set.prototype.isSubsetOf, isSupersetOf, and isDisjointFrom without array copies.
Code
const userScopes = new Set(['read:orders', 'write:orders', 'export:csv']);
const requiredForExport = new Set(['read:orders', 'export:csv']);
const restrictedAdminScopes = new Set(['delete:tenant', 'impersonate']);
// Check policy preconditions without converting Sets into temporary arrays
const hasAccess = requiredForExport.isSubsetOf(userScopes);
const userCoversAll = userScopes.isSupersetOf(requiredForExport);
const noConflict = userScopes.isDisjointFrom(restrictedAdminScopes);
console.log('hasAccess:', hasAccess, '| coversAll:', userCoversAll, '| noConflict:', noConflict);
const elevated = new Set([...userScopes, 'impersonate']);
console.log('elevated safe?:', elevated.isDisjointFrom(restrictedAdminScopes));Output
Captured from a sandboxed run of this snippet in the build pipeline.
hasAccess: true | coversAll: true | noConflict: true
elevated safe?: falseLogic trace — Set isSubsetOf and isDisjointFrom Check Policy
The file’s state is a handful of top-level bindings: userScopes, requiredForExport, restrictedAdminScopes, hasAccess.
Caveats
- No third-party code is loaded at any point while this runs.
Using it
The run emits 2 labeled sections — hasAccess:, elevated safe?: — one per step.
Key statements
const userScopes = new Set(['read:orders', 'write:orders', 'export:csv']);
const restrictedAdminScopes = new Set(['delete:tenant', 'impersonate']);
const requiredForExport = new Set(['read:orders', 'export:csv']);
Interactive Tools for This Topic
CORS Header Policy DebuggerSimulate browser CORS preflight and credential policies against server response headers to pinpoint blocked origins, methods, or headers and fix them.Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.CSP Header BuilderBuild a Content-Security-Policy header from per-directive sources, skipping empty ones and rejecting a blanket wildcard.
FAQ
- Is anything beyond the standard library required?
- Nothing beyond the standard library — the snippet is dependency-free. Its state lives in module-level bindings: `userScopes`, `requiredForExport`, `restrictedAdminScopes`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.