url-whitelist can create whitelists by including and excluding url patterns and check urls against them
create whitelists by including and excluding url patterns and check urls against them
see url-pattern for supported url patterns
npm install git://github.com/snd/url-whitelist.git
Whitelist = require 'url-whitelist'
whitelistcheck '/users/1' # => truewhitelistcheck '/projects/1' # => false
by default a whitelist excludes everything. to include everything by default and then selectively exclude do:
blacklist =blacklistinclude '*'blacklistexclude '/users/:id'blacklistcheck 'sajdflkasjdfl' # => trueblacklistcheck '/users/:id' # => falseblacklistcheck 'skljdf' # => true
/projects/* except for
Whitelist = require 'whitelist'whitelist =whitelistinclude '/projects/*'whitelistexclude '/projects/hidden/*'whitelistexclude '/projects/:id/secret'whitelistinclude '/users/:id'whitelistcheck '/projects/foo/bar/baz' # => truewhitelistcheck '/projects/hidden/bar/baz' # => falsewhitelistcheck '/projects/5/secret' # => falsewhitelistcheck '/projects/5/secret/foo' # => truewhitelistcheck '/users' # => falsewhitelistcheck '/users/5' # => truewhitelistcheck '/tasks/57' # => false
whitelisted = falsego through all include- and exclude-patterns in the order they were defined:if url matches patternif is includewhitelisted = trueelsewhitelisted = false
url-whitelist is released under the MIT License (see LICENSE for details).