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.0 to 1.0.1

2

package.json
{
"name": "function-overloader",
"version": "1.0.0",
"version": "1.0.1",
"description": "improve overloading functions and methods in js",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -7,1 +7,76 @@ # FUNCTION OVERLOADER

Introduce the mechanism for easy overloading functions and method.
## install
```
npm install function-overloader
```
## teaser
```
import Overload from "function-overloader";
class Monster {
constructor() {
Overload.set(...arguments)
.when("string", "number")
.do((monsterName, level) => {
this.name = monsterName;
this.level = level;
})
.when("object")
.do(monsterData => {
this.name = monsterData.name;
this.level = monsterData.level;
})
.when()
.do(() => {
throw Error("Wrong attributes);
})
.done();
console.log(`Monster ${this.name}` level ${this.level} created`);
}
addAttribute() {
return Overload.set(...arguments)
.when(Attribute)
.do(this.addExisitingAttribute)
.when("string", "function")
.do(this.addNewAttribute)
.when()
.do(() => {
throw Error("Wrong attributes);
})
.done();
}
addExisitingAttribute (attribute) {
this.attributes.push(attribute);
return attribute;
}
addNewAttribute (attributeName, attributeLogic) {
const attribute = new Attribute(attributeName, attributeLogic);
this.attributes.push(attribute);
return attribute;
}
}
```
Now it is possible:
```
const monster1 = new Monster ("hakuna", 3);
monster1.addAttribute("happy", () => {});
const attribute = new Attribute("sad", () => {});
monster1.addAttribute(attribute);
const monster2 = new Monster ({
name: "froggy",
level: 2
});
```

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