dist/modules/function.js
function tryWrap(fn) {
    var args = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        args[_i - 1] = arguments[_i];
    }
    return function (def) {
        try {
            return fn.apply(void 0, args);
        }
        catch (ex) {
            if (is_1.isFunction(def))
                return def(ex);
            return to_1.toDefault(def);
        }
    };
}
function tryWrap(fn) {
    var args = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        args[_i - 1] = arguments[_i];
    }
    return function (def) {
        try {
            return fn.apply(void 0, args);
        }
        catch (ex) {
            if (is_1.isFunction(def))
                return def(ex);
            return to_1.toDefault(def);
        }
    };
}
function tryWrap ( fn ) { var args = [ ] ; for ( var _i = 1 ; _i < arguments . length ; _i ++ ) { args [ _i - 1 ] = arguments [ _i ] ; } return function ( def ) { try { return fn . apply ( void 0 , args ) ; } catch ( ex ) { if ( is_1 . isFunction ( def ) ) return def ( ex ) ; return to_1 . toDefault ( def ) ; } } ; }
Try Wrap
Generic helper for calling try catch on a method.
If a default method is provided it will return in on error
otherwise it will return null.

@example
function func(val: any) { return isString(val); }
const result = tryWrap(func)();

With params
tryWrap(JSON.stringify, { name: 'Adele', age: 30 }, null, 2)()

With default
tryWrap(Number, '30')(35);
Where '35' is the default value on error.

@param fn the parse method to be called in try/parse block.
@param args arguments to pass to above method.
Try Wrap Generic helper for calling try catch on a method . If a default method is provided it will return in on error otherwise it will return null .