Checks whether a subset is contained in a list of scopes. Uses code generation
npm install validate-scope
Checks whether a subset is contained in a list of scopes.
Uses code generation to reach better performance.
``js
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
`
`js`
const validateScope = require('validate-scope')
`js`
const validate = validateScope(array|string)
validate(array|string) // returns boolean
`js`
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
`bash
NANOBENCH version 1