{"id":16531383,"url":"https://github.com/marcbachmann/validate-scope","last_synced_at":"2025-07-03T22:04:40.788Z","repository":{"id":57390268,"uuid":"73310312","full_name":"marcbachmann/validate-scope","owner":"marcbachmann","description":"Checks whether a subset is contained in a list of oauth scopes. Uses code generation to reach better performance.","archived":false,"fork":false,"pushed_at":"2023-12-15T17:33:06.000Z","size":56,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-03T22:03:53.951Z","etag":null,"topics":["boolean-expression","jwt","oauth","scope","subset","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcbachmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-09T18:30:03.000Z","updated_at":"2023-04-24T12:10:08.000Z","dependencies_parsed_at":"2023-12-15T18:44:32.401Z","dependency_job_id":null,"html_url":"https://github.com/marcbachmann/validate-scope","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/marcbachmann/validate-scope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fvalidate-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fvalidate-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fvalidate-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fvalidate-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcbachmann","download_url":"https://codeload.github.com/marcbachmann/validate-scope/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fvalidate-scope/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263410760,"owners_count":23462295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boolean-expression","jwt","oauth","scope","subset","validation"],"created_at":"2024-10-11T18:08:41.701Z","updated_at":"2025-07-03T22:04:40.726Z","avatar_url":"https://github.com/marcbachmann.png","language":"JavaScript","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 \u0026\u0026 second \u0026\u0026 !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 \u0026 array indexOf\n  end ~8.58 s (8 s + 583230771 ns)\n# traditional for loop \u0026 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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbachmann%2Fvalidate-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcbachmann%2Fvalidate-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbachmann%2Fvalidate-scope/lists"}