
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
validate-scope
Advanced tools
Checks whether a subset is contained in a list of scopes. Uses code generation
Checks whether a subset is contained in a list of scopes. Uses code generation to reach better performance.
const validateScope = require('validate-scope')
// Check only one scope
const validate = validateScope(['user:edit'])
// pass an array
validate(['profile', 'user:edit']) // returns true
validate(['profile', 'another-scope']) // returns false
// or a string of scopes separated by whitespaces
validate('profile user:edit user:archive') // returns true
// or check multiple scopes
const validate = validateScope('user:edit AND user:archive')
validate('profile user:edit') // returns false
validate('profile user:edit user:archive') // returns true
// you can use more complex boolean expressions
const validate = validateScope('first && second && !third')
validate(['first']) // returns false
validate(['first', 'second']) // returns true
validate(['first', 'second', 'third']) // returns false
const validateScope = require('validate-scope')
const validate = validateScope(array|string)
validate(array|string) // returns boolean
const validate = validateScope('(user:edit AND user:archive) OR admin)')
validate.scopes
// ['user:edit', 'user:archive', 'admin']
I suggest you to save your scopes as array and also pass that to this validation method. String operations are quite slow.
100000000 iterations each
NANOBENCH version 1
# validate("some space separate scopes")
end ~3.51 s (3 s + 513290216 ns)
# validate(["some", "scopes", "as", "array"])
end ~599 ms (0 s + 598547467 ns)
# traditional string split & array indexOf
end ~8.58 s (8 s + 583230771 ns)
# traditional for loop & array indexOf
end ~694 ms (0 s + 693684995 ns)
# total ~13 s (13 s + 388753449 ns)
# ok
FAQs
Checks whether a subset is contained in a list of scopes. Uses code generation
The npm package validate-scope receives a total of 1,963 weekly downloads. As such, validate-scope popularity was classified as popular.
We found that validate-scope demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.