{"_id":"validate-scope","_rev":"10-62a21bb1c4a907280a5d767608efe055","name":"validate-scope","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","dist-tags":{"latest":"1.3.0"},"versions":{"1.0.0":{"name":"validate-scope","version":"1.0.0","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","main":"index.js","keywords":["scope","subset","oauth","jwt","validate"],"scripts":{"test":"standard && node test.js"},"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"license":"ISC","devDependencies":{"nanobench":"^1.0.1","standard":"^8.5.0"},"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","gitHead":"a97910c5660745d3f7868065ab181a19bccd164e","_id":"validate-scope@1.0.0","_shasum":"37ecfabdf1fb3f52f92b26744d930e927f3e0fec","_from":".","_npmVersion":"3.10.8","_nodeVersion":"4.4.7","_npmUser":{"name":"marcbachmann","email":"marc.brookman@gmail.com"},"dist":{"shasum":"37ecfabdf1fb3f52f92b26744d930e927f3e0fec","tarball":"https://registry.npmjs.org/validate-scope/-/validate-scope-1.0.0.tgz","integrity":"sha512-5vvSwRUkGkqLMjC8YtxN1DwumMVka62s+rTpRPhaHdDzHyuDXxq4/RgvMA+Ft8F54vt7yjK1G4UYcMM2m1I7zw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIADw3jTgMiAvgzUr42GiwLsMGh+mql1PBsJGxkYDvv+OAiEAllZDwMjifR4c9MJ5jLz8Ax63VGmaeglQGN1viDav+PY="}]},"maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/validate-scope-1.0.0.tgz_1478716362402_0.35141995642334223"},"directories":{}},"1.1.0":{"name":"validate-scope","version":"1.1.0","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","main":"index.js","keywords":["scope","subset","oauth","jwt","validate"],"scripts":{"test":"standard && node test.js"},"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"license":"ISC","devDependencies":{"nanobench":"^1.0.1","standard":"^8.5.0"},"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","gitHead":"1f6d61a25553abab58ab55c7bed2528e36b92dfd","_id":"validate-scope@1.1.0","_shasum":"f786bab06f121fc86c300cfb77a2f48730f050dc","_from":".","_npmVersion":"3.10.8","_nodeVersion":"4.4.7","_npmUser":{"name":"marcbachmann","email":"marc.brookman@gmail.com"},"dist":{"shasum":"f786bab06f121fc86c300cfb77a2f48730f050dc","tarball":"https://registry.npmjs.org/validate-scope/-/validate-scope-1.1.0.tgz","integrity":"sha512-2jEGlq1DyKZEqejluvGvgPVzZ/3abl7TUR9z5XlG41rxABWEqy0ThvUKSxBhkZg2vLhATe3FkIypLeFlKPclCg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGO3ZSNr74PBiPTpEO1NMwRpT5sS9HZ0N2o/D26rW+YcAiAC5WAZycoCrWu2DoBYpaUinMP0sDKj745klkihfqno8w=="}]},"maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/validate-scope-1.1.0.tgz_1478822418006_0.5298169346060604"},"directories":{}},"1.1.1":{"name":"validate-scope","version":"1.1.1","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","main":"index.js","keywords":["scope","subset","oauth","jwt","validate","expression","boolean"],"scripts":{"test":"standard && node test.js"},"files":["index.js"],"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"license":"ISC","devDependencies":{"nanobench":"^1.0.1","standard":"^8.5.0"},"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","gitHead":"594c2e3447fe8000251b00baf00fd6f1059a4e82","_id":"validate-scope@1.1.1","_shasum":"b1e26f2f22c679958fc33a604ff79cb36de0f884","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"marcbachmann","email":"marc.brookman@gmail.com"},"dist":{"shasum":"b1e26f2f22c679958fc33a604ff79cb36de0f884","tarball":"https://registry.npmjs.org/validate-scope/-/validate-scope-1.1.1.tgz","integrity":"sha512-GxKpINZyYrBNMex/Tl2oBJlN/q4G3F13MgHmVT8DPOCxDBVcFDmlFATaar/rDTNg2/QirDp2aX9zCsHIDwNQlQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDfxsbXeUrqiNwmotOEHylv5am/soclzTSnhvpQ9yhkOgIgB94hZfXSGzI9pN44Pa3A/hWLrAZMHc28jGDQdRREXjA="}]},"maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/validate-scope-1.1.1.tgz_1482699301604_0.03960696258582175"},"directories":{}},"1.2.0":{"name":"validate-scope","version":"1.2.0","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","main":"index.js","keywords":["scope","subset","oauth","jwt","validate","expression","boolean"],"scripts":{"test":"standard && node test.js"},"files":["index.js"],"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"license":"ISC","devDependencies":{"nanobench":"^1.0.1","standard":"^8.5.0"},"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","dependencies":{"boolean-expression":"^2.0.0"},"gitHead":"7ca0c86a63c9b0144e79373451fc94795bb7cbaa","_id":"validate-scope@1.2.0","_shasum":"d7e47174dae4035d7a201241b6f15de56a4f8b72","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.4","_npmUser":{"name":"marcbachmann","email":"marc.brookman@gmail.com"},"dist":{"shasum":"d7e47174dae4035d7a201241b6f15de56a4f8b72","tarball":"https://registry.npmjs.org/validate-scope/-/validate-scope-1.2.0.tgz","integrity":"sha512-P7GvhZqQPl363FyNj8JI81m7uHxVUGDsMVwT646SKjmPh/jhBV3OBdebpobQdSAMHuXjCapS/JGyuyOAQRu7qA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCUwXm9G9hehCIMuobx9MhkDsF24osStaOUjuQzl/aVhgIhAMON43Ovf6GBQ3e0l6yQJaIoF/QgQTEi3wD/x4TxEd0/"}]},"maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/validate-scope-1.2.0.tgz_1485877143944_0.8109093056991696"},"directories":{}},"1.3.0":{"name":"validate-scope","version":"1.3.0","description":"Checks whether a subset is contained in a list of scopes. Uses code generation","main":"index.js","keywords":["scope","subset","oauth","jwt","validate","expression","boolean"],"scripts":{"test":"standard && node test.js"},"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"license":"ISC","devDependencies":{"nanobench":"^2.0.0","standard":"^11.0.0"},"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","dependencies":{"boolean-expression":"^2.0.0"},"gitHead":"a4a115ee7394bc75030eaa31907935fc2d7fc74f","_id":"validate-scope@1.3.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-loK9DPbZAhrG1276cUjidSpzkl/5s219ERm8LdSffBVvDDs9k9z9/+Cj4ljYyfegls8uL1Oz4wmsMPVBKX1nng==","shasum":"8a0b7ea763e1d147d11fa697bddc3121e4c9edef","tarball":"https://registry.npmjs.org/validate-scope/-/validate-scope-1.3.0.tgz","fileCount":3,"unpackedSize":4398,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFGCJXqg0ExbLnudr6pgmS4OKG+Gx8L2FP2bsPfGNzu8AiEA8uvrngA/ojWeEyzHsHWWCCTGmbiOcWoOyJ8aGEQmIC8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkRnKdACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoQXw/+P811cMsTZLcoqK82QqYRcso9xCUUYLKDu3b/3ueElt3iroYB\r\nPOV6JWT+ApCJIAJjH7f0zboi6TaXl4JdYZ6ULT14l8hbzr3YHQ4HurEHesFM\r\nHBYuNjHsc8sxGDJBrevZiRiRCvqa6O+X1GUSi73eSNHRI7g+E1ex6MVA/qZX\r\nJu5GXBHVXDgn5I01hFEvyZLxwVsZrL7PthncN4Qblmhx9GqCj5j6oPFq9igu\r\nNK72KaS181FbmaHMfCOjLZtQCKZ2sSa9PvkKrZ4fSiGAxMdr2UhBUcrewQzv\r\n16QApzhAgz0fAAL7k/9e7Q06KW1WZOUp80nG2AG4k8oToKlW/ox3UBcv4bp8\r\nq5sAcxzCKboGQgNoNMi07S0asIRipRgzp8sZlVz8xrddsUlTzAnwFb9/h+Fg\r\ntHWxtiIrCFbfsVw07QphoVOQdl7I+iaCggjFXejUWY6yLMKzfMz2OUkSyGu7\r\n0OJ0fK1ajqTPqOyluy+o7cTK6hQxvW1H/Bd6y84QPxlsPJiY6CoY717RK9KH\r\nREJHZOd/IedPbD85gax2JoDq/jZHHM67QGiNGdlylsZVwUPjLigdK06qD7Yj\r\n0Wgnz+Afoi8Th8l+uB+YLV/rPhZVR4VX9uWfDcUfwg9G1o2iABaVq4wv2VFM\r\nRy4ESqN/8/BUUS0nM4BeDJNpqZX3x2mwk0w=\r\n=oyt7\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"marcbachmann","email":"marc.brookman@gmail.com"},"directories":{},"maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/validate-scope_1.3.0_1682338461535_0.8349342335413807"},"_hasShrinkwrap":false}},"readme":"# validate-scope\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmarcbachmann%2Fvalidate-scope.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmarcbachmann%2Fvalidate-scope?ref=badge_shield)\n\n\nChecks whether a subset is contained in a list of scopes.\nUses code generation to reach better performance.\n\n```js\nconst validateScope = require('validate-scope')\n\n// Check only one scope\nconst validate = validateScope(['user:edit'])\n\n// pass an array\nvalidate(['profile', 'user:edit']) // returns true\nvalidate(['profile', 'another-scope']) // returns false\n\n// or a string of scopes separated by whitespaces\nvalidate('profile user:edit user:archive') // returns true\n\n// or check multiple scopes\nconst validate = validateScope('user:edit AND user:archive')\nvalidate('profile user:edit') // returns false\nvalidate('profile user:edit user:archive') // returns true\n\n// you can use more complex boolean expressions\nconst validate = validateScope('first && second && !third')\nvalidate(['first']) // returns false\nvalidate(['first', 'second']) // returns true\nvalidate(['first', 'second', 'third']) // returns false\n```\n\n# Api\n\n```js\nconst validateScope = require('validate-scope')\n```\n\n```js\nconst validate = validateScope(array|string)\nvalidate(array|string) // returns boolean\n```\n\n\n```js\nconst validate = validateScope('(user:edit AND user:archive) OR admin)')\nvalidate.scopes\n// ['user:edit', 'user:archive', 'admin']\n```\n\n\nI suggest you to save your scopes as array and also pass that to this validation method. String operations are quite slow.\n\n\n# Benchmark\n\n100000000 iterations each\n```bash\nNANOBENCH version 1\n\n# validate(\"some space separate scopes\")\n  end ~3.51 s (3 s + 513290216 ns)\n# validate([\"some\", \"scopes\", \"as\", \"array\"])\n  end ~599 ms (0 s + 598547467 ns)\n# traditional string split & array indexOf\n  end ~8.58 s (8 s + 583230771 ns)\n# traditional for loop & array indexOf\n  end ~694 ms (0 s + 693684995 ns)\n\n# total ~13 s (13 s + 388753449 ns)\n\n# ok\n```\n\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmarcbachmann%2Fvalidate-scope.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmarcbachmann%2Fvalidate-scope?ref=badge_large)\n","maintainers":[{"name":"marcbachmann","email":"marc.brookman@gmail.com"}],"time":{"modified":"2023-04-24T12:14:21.788Z","created":"2016-11-09T18:32:44.173Z","1.0.0":"2016-11-09T18:32:44.173Z","1.1.0":"2016-11-11T00:00:20.094Z","1.1.1":"2016-12-25T20:55:03.808Z","1.2.0":"2017-01-31T15:39:05.805Z","1.3.0":"2023-04-24T12:14:21.683Z"},"homepage":"https://github.com/marcbachmann/validate-scope#readme","keywords":["scope","subset","oauth","jwt","validate","expression","boolean"],"repository":{"type":"git","url":"git+https://github.com/marcbachmann/validate-scope.git"},"author":{"name":"Marc Bachmann","email":"marc.brookman@gmail.com"},"bugs":{"url":"https://github.com/marcbachmann/validate-scope/issues"},"license":"ISC","readmeFilename":"README.md","users":{"marcbachmann":true}}