return-style
Advanced tools
Comparing version 0.1.0 to 0.1.1
export declare function returnResultFromAsyncFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>): (...args: U) => Promise<T | null>; | ||
export declare function returnResultFromAsyncFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>, defaultValue: T): (...args: U) => Promise<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function returnResultFromAsyncFunction(fn) { | ||
function returnResultFromAsyncFunction(fn, defaultValue = null) { | ||
return async function (...args) { | ||
@@ -8,4 +8,4 @@ try { | ||
} | ||
catch (err) { | ||
return null; | ||
catch { | ||
return await Promise.resolve(defaultValue); | ||
} | ||
@@ -12,0 +12,0 @@ }; |
export declare function returnResultFromFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>): (...args: U) => Promise<T | null>; | ||
export declare function returnResultFromFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>, defaultValue: T): (...args: U) => Promise<T>; | ||
export declare function returnResultFromFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => T): (...args: U) => T | null; | ||
export declare function returnResultFromFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => T, defaultValue: T): (...args: U) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const extra_promise_1 = require("extra-promise"); | ||
function returnResultFromFunction(fn) { | ||
function returnResultFromFunction(fn, defaultValue = null) { | ||
return function (...args) { | ||
@@ -10,4 +10,4 @@ let result; | ||
} | ||
catch (err) { | ||
return null; | ||
catch { | ||
return defaultValue; | ||
} | ||
@@ -19,4 +19,4 @@ if (extra_promise_1.isPromise(result)) { | ||
} | ||
catch (err) { | ||
return null; | ||
catch { | ||
return defaultValue; | ||
} | ||
@@ -23,0 +23,0 @@ })(result); |
export declare function returnResultFromPromise<T>(promise: PromiseLike<T>): Promise<T | null>; | ||
export declare function returnResultFromPromise<T>(promise: PromiseLike<T>, defaultValue: T): Promise<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function returnResultFromPromise(promise) { | ||
function returnResultFromPromise(promise, defaultValue = null) { | ||
return (async () => { | ||
@@ -8,4 +8,4 @@ try { | ||
} | ||
catch (err) { | ||
return null; | ||
catch { | ||
return defaultValue; | ||
} | ||
@@ -12,0 +12,0 @@ })(); |
export declare function returnResultFromSyncFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => T): (...args: U) => T | null; | ||
export declare function returnResultFromSyncFunction<T, U extends unknown[] = any[]>(fn: (...args: U) => T, defaultValue: T): (...args: U) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function returnResultFromSyncFunction(fn) { | ||
function returnResultFromSyncFunction(fn, defaultValue = null) { | ||
return function (...args) { | ||
@@ -8,4 +8,4 @@ try { | ||
} | ||
catch (err) { | ||
return null; | ||
catch { | ||
return defaultValue; | ||
} | ||
@@ -12,0 +12,0 @@ }; |
export declare function returnResult<T>(promise: PromiseLike<T>): Promise<T | null>; | ||
export declare function returnResult<T>(promise: PromiseLike<T>, defaultValue: T): Promise<T>; | ||
export declare function returnResult<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>): (...args: U) => Promise<T | null>; | ||
export declare function returnResult<T, U extends unknown[] = any[]>(fn: (...args: U) => PromiseLike<T>, defaultValue: T): (...args: U) => Promise<T>; | ||
export declare function returnResult<T, U extends unknown[] = any[]>(fn: (...args: U) => T): (...args: U) => T | null; | ||
export declare function returnResult<T, U extends unknown[] = any[]>(fn: (...args: U) => T, defaultValue: T): (...args: U) => T; |
@@ -5,8 +5,8 @@ "use strict"; | ||
const return_result_from_promise_1 = require("./return-result-from-promise"); | ||
function returnResult(promiseOrFn) { | ||
function returnResult(promiseOrFn, defaultValue = null) { | ||
if (typeof promiseOrFn === 'function') { | ||
return return_result_from_function_1.returnResultFromFunction(promiseOrFn); | ||
return return_result_from_function_1.returnResultFromFunction(promiseOrFn, defaultValue); | ||
} | ||
else { | ||
return return_result_from_promise_1.returnResultFromPromise(promiseOrFn); | ||
return return_result_from_promise_1.returnResultFromPromise(promiseOrFn, defaultValue); | ||
} | ||
@@ -13,0 +13,0 @@ } |
{ | ||
"name": "return-style", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33383
445