Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

function-overloader

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

function-overloader - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc