0.1.2 • Published 8 years ago

safe-decorator v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Build Status

safe-decorator

decorator function to catch and return default value

##usage

###@safe or @safe() method with @safe or @safe() will return null when exception thrown.

import safe from 'safe-decorator';

class Subject {
    @safe
    subjectMethod() {
        throw new Error('error');
    }
}

const subject = new Subject();
expect(subject.subjectMethod()).toBe(null);

###@safe(defaultValue) method with @safe(defaultValue) return defaultValue when exception thrown.

import safe from 'safe-decorator';

class Subject {
    @safe('default value')
    subjectMethod() {
        throw new Error('error');
    }
}

const subject = new Subject();
expect(subject.subjectMethod()).toBe('default value');