function-overloader
Advanced tools
Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "function-overloader", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "improve overloading functions and methods in js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import debug from "debug"; | ||
/** | ||
* Class representing helper for methods for simplify overloading | ||
*/ | ||
export default class Overload { | ||
@@ -63,2 +61,16 @@ static set() { | ||
else(callback) { | ||
this._debug("else"); | ||
if (this._enabled) { | ||
this._debug("execute function"); | ||
this._enabled = false; | ||
let result = callback(...this._args); | ||
this._debug("function sync result", result); | ||
this._result = result; | ||
} | ||
return this; | ||
} | ||
/** | ||
@@ -65,0 +77,0 @@ * Should be called at the end. It will return result from called use callback |
@@ -50,2 +50,15 @@ import Overload from "./Overload"; | ||
it("invoke else and correct response when no condition met", () => { | ||
let result = Overload.set(10, 10) | ||
.when("number", "string") | ||
.do(() => "wrong result") | ||
.when() | ||
.do(() => "wrong result") | ||
.when("number", "object") | ||
.do(() => "wrong result") | ||
.else(() => "correct result") | ||
.done(); | ||
expect(result).to.be.equal("correct result"); | ||
}); | ||
it("return sync result for classes", () => { | ||
@@ -52,0 +65,0 @@ class Test1 {} |
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
72441
375