Function to provide a similar syntax to a switch statement but with regex as cases.
I tried to mimic the syntax of a switch statement as good as possible. The following example shows how to match against the UserAgent string to detect iOS devices.
switchernavigatoruserAgentconsole.log'iOS device. '+scope+' did match '+expression;console.log'any device.';;
breakMode set to
true no cases after the default one could be reached.
switcherscope tests options;
Options can be changed by passing an object as third parameter to switcher.
When set to
true (which is default) switcher will stop testing after the first match. When set to
false switcher will continue testing (but note that changes that may have been made by previous matches can be overwritten ‒ especially if you have a default case at the end).