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

@aeroware/overload.js

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aeroware/overload.js

![logo](./overloadjs.png)]

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

overload.js

logo]

Overload.js is a micro-library here to make overloading functions incredibly easy.

Contrary to other overloading libraries out there, Overload.js does not use method chaining to give you overloading.

Instead, Overload.js is a wrapper function that takes only one argument: the overloads.

Here is an example using Overload.js:

const OverloadJS = require("@aeroware/overload.js");

const overloadedFunction = OverloadJS({
    ["string number? object"](str, num) {
        console.log("callback 1 executed");
    },
    ["string boolean number?"](str, bool, num) {
        console.log("callback 2 executed");
    },
});

overloadedFunction("hello world", 420, {});  // => "callback 1 executed"
overloadedFunction("hello world", true, 69); // => "callback 2 executed"
overloadedFunction("hello world", {});       // !! No overload matches this call.

Overloads follow a simple syntax, and there are currently on 4 supported types, all of which can be nullable:

  • string
  • number
  • boolean
  • object

To make a parameter nullable (and undefined-able), simply place a ? after the parameter:

  • string?
  • number?
  • boolean?
  • object?

If you have any trouble, you can join us at Discord and ask!

FAQs

Package last updated on 01 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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