ts-guard-decorator 🛡
Decorator for running a check before running a method.
Installation
npm install --save ts-guard-decorator
Usage
Decorators are supported in TypeScript or with Babel.
; // Don't run `myFunc` if `window` doesn't exist @ { // ... }
This is equivalent to writing:
{ if typeof window === 'undefined' return; // ... }
Arguments
The guard accepts 2 arguments:
- A boolean expression (i.e. something that evaluates to
true
orfalse
) indicating whether the method should run. - A optional return value if the method should not run.
{ return arg1 === arg2;} @ { return true; } //=> true @ { return true; } //=> undefined @ { return true; } //=> true @ { return true; } //=> "hello" @ { return true; } //=> true @ { return true; } //=> "hello"