function-overloader
Advanced tools
Comparing version 1.0.5 to 1.1.0
{ | ||
"name": "function-overloader", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "improve overloading functions and methods in js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,6 +39,2 @@ # FUNCTION OVERLOADER | ||
}) | ||
.when() | ||
.do(() => { | ||
throw Error("Wrong attributes"); | ||
}) | ||
.done(); | ||
@@ -54,6 +50,2 @@ console.log(`Monster ${this.name} level ${this.level} created`); | ||
.do(this.addNewAttribute) | ||
.when() | ||
.do(() => { | ||
throw Error("Wrong attributes"); | ||
}) | ||
.done(); | ||
@@ -167,2 +159,4 @@ } | ||
if there is no arguments it means that it will resolve only when overloaded function doesn't get any arguments. | ||
```javascript | ||
@@ -175,3 +169,3 @@ .done() | ||
### Function Respons | ||
### Function Response | ||
@@ -178,0 +172,0 @@ Has one method |
@@ -25,14 +25,19 @@ /** | ||
when() { | ||
let checkCondition = Array.from(arguments).every((arg, index) => { | ||
switch (typeof arg) { | ||
// means that this is expected typeof argument | ||
case "string": | ||
return typeof this._args[index] === arg; | ||
// means that this is function which positive result means that this is expected argument | ||
case "function": | ||
return this._args[index] instanceof arg; | ||
default: | ||
throw TypeError("Wrong arguments", arg); | ||
} | ||
}); | ||
let checkCondition = false; | ||
if (arguments.length === 0 && this._args.length === 0) { | ||
checkCondition = true; | ||
} else if (arguments.length === this._args.length) { | ||
checkCondition = Array.from(arguments).every((arg, index) => { | ||
switch (typeof arg) { | ||
// means that this is expected typeof argument | ||
case "string": | ||
return typeof this._args[index] === arg; | ||
// means that this is function which positive result means that this is expected argument | ||
case "function": | ||
return this._args[index] instanceof arg; | ||
default: | ||
throw TypeError("Wrong arguments", arg); | ||
} | ||
}); | ||
} | ||
return { | ||
@@ -39,0 +44,0 @@ do: callback => { |
@@ -14,4 +14,6 @@ import Overload from "./Overload"; | ||
expect(result).to.be.equal("correct result"); | ||
}); | ||
result = Overload.set(undefined, 12345) | ||
it("return correct response when expected undefined as argument", () => { | ||
let result = Overload.set(undefined, 12345) | ||
.when("number", "string") | ||
@@ -27,2 +29,24 @@ .do(() => "wrong result") | ||
it("return correct response when expected no arguments", () => { | ||
let result = Overload.set() | ||
.when("number", "string") | ||
.do(() => "wrong result") | ||
.when() | ||
.do(() => "correct result") | ||
.when("number", "object") | ||
.do(() => "wrong result") | ||
.done(); | ||
expect(result).to.be.equal("correct result"); | ||
result = Overload.set() | ||
.when("undefined", "undefined") | ||
.do(() => "wrong resultAA") | ||
.when() | ||
.do(() => "correct result") | ||
.when("number", "object") | ||
.do(() => "wrong result") | ||
.done(); | ||
expect(result).to.be.equal("correct result"); | ||
}); | ||
it("return sync result for classes", () => { | ||
@@ -29,0 +53,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
68499
346
179