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.10.2 to 1.10.3

src/checkCondition.js

196

dist/index.js

@@ -121,4 +121,2 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -130,43 +128,51 @@

var _number = __webpack_require__(5);
var _checkCondition = __webpack_require__(5);
var _checkCondition2 = _interopRequireDefault(_checkCondition);
var _createType = __webpack_require__(7);
var _createType2 = _interopRequireDefault(_createType);
var _number = __webpack_require__(8);
var _number2 = _interopRequireDefault(_number);
var _string = __webpack_require__(6);
var _string = __webpack_require__(9);
var _string2 = _interopRequireDefault(_string);
var _object = __webpack_require__(7);
var _object = __webpack_require__(10);
var _object2 = _interopRequireDefault(_object);
var _array = __webpack_require__(8);
var _array = __webpack_require__(11);
var _array2 = _interopRequireDefault(_array);
var _boolean = __webpack_require__(9);
var _boolean = __webpack_require__(12);
var _boolean2 = _interopRequireDefault(_boolean);
var _function = __webpack_require__(10);
var _function = __webpack_require__(13);
var _function2 = _interopRequireDefault(_function);
var _symbol = __webpack_require__(11);
var _symbol = __webpack_require__(14);
var _symbol2 = _interopRequireDefault(_symbol);
var _undefined = __webpack_require__(12);
var _undefined = __webpack_require__(15);
var _undefined2 = _interopRequireDefault(_undefined);
var _instance = __webpack_require__(13);
var _instance = __webpack_require__(16);
var _instance2 = _interopRequireDefault(_instance);
var _null = __webpack_require__(14);
var _null = __webpack_require__(17);
var _null2 = _interopRequireDefault(_null);
var _any = __webpack_require__(15);
var _any = __webpack_require__(18);

@@ -181,10 +187,2 @@ var _any2 = _interopRequireDefault(_any);

function createType(typeCondition) {
return function (input) {
return { execute: function execute(arg) {
return typeCondition(arg, input);
} };
};
}
var Overload = function () {

@@ -232,3 +230,3 @@ _createClass(Overload, null, [{

this._debug("when", Array.from(arguments));
var conditionResult = checkCondition(arguments, this._args);
var conditionResult = (0, _checkCondition2.default)(arguments, this._args);
this._debug("result", conditionResult);

@@ -297,21 +295,44 @@ return {

Overload.NUMBER = createType(_number2.default);
Overload.STRING = createType(_string2.default);
Overload.OBJECT = createType(_object2.default);
Overload.ARRAY = createType(_array2.default);
Overload.BOOLEAN = createType(_boolean2.default);
Overload.FUNCTION = createType(_function2.default);
Overload.SYMBOL = createType(_symbol2.default);
Overload.UNDEFINED = createType(_undefined2.default);
Overload.NULL = createType(_null2.default);
Overload.ANY = createType(_any2.default);
Overload.INSTANCE = createType(_instance2.default);
Overload.NUMBER = (0, _createType2.default)(_number2.default);
Overload.STRING = (0, _createType2.default)(_string2.default);
Overload.OBJECT = (0, _createType2.default)(_object2.default);
Overload.ARRAY = (0, _createType2.default)(_array2.default);
Overload.BOOLEAN = (0, _createType2.default)(_boolean2.default);
Overload.FUNCTION = (0, _createType2.default)(_function2.default);
Overload.SYMBOL = (0, _createType2.default)(_symbol2.default);
Overload.UNDEFINED = (0, _createType2.default)(_undefined2.default);
Overload.NULL = (0, _createType2.default)(_null2.default);
Overload.ANY = (0, _createType2.default)(_any2.default);
Overload.INSTANCE = (0, _createType2.default)(_instance2.default);
exports.default = Overload;
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = require("debug");
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = checkCondition;
var _checkTypeCondition = __webpack_require__(6);
var _checkTypeCondition2 = _interopRequireDefault(_checkTypeCondition);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function checkCondition(conditionArguments, testedArguments) {
if (conditionArguments.length === testedArguments.length) {
return Array.from(conditionArguments).every(function (typeFunction, index) {
return Array.from(conditionArguments).every(function (conditionArgument, index) {
var testedArgument = testedArguments[index];
return checkTypeCondition(typeFunction, testedArgument);
return (0, _checkTypeCondition2.default)(conditionArgument, testedArgument, index, conditionArguments, testedArguments);
});

@@ -322,21 +343,80 @@ }

function checkTypeCondition(typeFunction, testedArgument) {
switch (typeof typeFunction === "undefined" ? "undefined" : _typeof(typeFunction)) {
case "function":
return typeFunction().execute(testedArgument);
case "object":
return typeFunction.execute(testedArgument);
default:
throw TypeError("Wrong arguments", typeFunction);
}
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = checkTypeCondition;
function checkTypeCondition(conditionArgument, testedArgument, index, conditionArguments, testedArguments) {
return [functionConditionArgument, objectConditionArgument, elseConditionArgument].map(function (conditionArgumentFactory) {
return conditionArgumentFactory(conditionArgument, testedArgument);
}).find(function (conditionArgumentObject) {
return conditionArgumentObject.test();
}).execute();
}
function functionConditionArgument(conditionArgument, testedArgument) {
return {
execute: function execute() {
return conditionArgument().execute(testedArgument);
},
test: function test() {
return typeof conditionArgument === "function";
}
};
}
function objectConditionArgument(conditionArgument, testedArgument) {
return {
execute: function execute() {
return conditionArgument.execute(testedArgument);
},
test: function test() {
return (typeof conditionArgument === "undefined" ? "undefined" : _typeof(conditionArgument)) === "object";
}
};
}
function elseConditionArgument(conditionArgument, testedArgument) {
return {
execute: function execute() {
throw TypeError("Wrong arguments", conditionArgument);
},
test: function test() {
return true;
}
};
}
/***/ }),
/* 4 */
/***/ (function(module, exports) {
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = require("debug");
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createType;
function createType(typeCondition) {
return function (typeInput) {
return {
execute: function execute(testedArgument) {
return typeCondition(testedArgument, typeInput);
}
};
};
}
/***/ }),
/* 5 */
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

@@ -356,3 +436,3 @@

/***/ }),
/* 6 */
/* 9 */
/***/ (function(module, exports, __webpack_require__) {

@@ -372,3 +452,3 @@

/***/ }),
/* 7 */
/* 10 */
/***/ (function(module, exports, __webpack_require__) {

@@ -390,3 +470,3 @@

/***/ }),
/* 8 */
/* 11 */
/***/ (function(module, exports, __webpack_require__) {

@@ -408,3 +488,3 @@

/***/ }),
/* 9 */
/* 12 */
/***/ (function(module, exports, __webpack_require__) {

@@ -424,3 +504,3 @@

/***/ }),
/* 10 */
/* 13 */
/***/ (function(module, exports, __webpack_require__) {

@@ -440,3 +520,3 @@

/***/ }),
/* 11 */
/* 14 */
/***/ (function(module, exports, __webpack_require__) {

@@ -458,3 +538,3 @@

/***/ }),
/* 12 */
/* 15 */
/***/ (function(module, exports, __webpack_require__) {

@@ -474,3 +554,3 @@

/***/ }),
/* 13 */
/* 16 */
/***/ (function(module, exports, __webpack_require__) {

@@ -490,3 +570,3 @@

/***/ }),
/* 14 */
/* 17 */
/***/ (function(module, exports, __webpack_require__) {

@@ -506,3 +586,3 @@

/***/ }),
/* 15 */
/* 18 */
/***/ (function(module, exports, __webpack_require__) {

@@ -509,0 +589,0 @@

{
"name": "function-overloader",
"version": "1.10.2",
"version": "1.10.3",
"description": "improve overloading functions and methods in js",

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

import debug from "debug";
import checkCondition from "./checkCondition";
import createType from "./createType";

@@ -15,6 +17,2 @@ import numberCondition from "./types/number";

function createType(typeCondition) {
return input => ({ execute: arg => typeCondition(arg, input) });
}
export default class Overload {

@@ -116,22 +114,1 @@ static NUMBER = createType(numberCondition);

}
function checkCondition(conditionArguments, testedArguments) {
if (conditionArguments.length === testedArguments.length) {
return Array.from(conditionArguments).every((typeFunction, index) => {
const testedArgument = testedArguments[index];
return checkTypeCondition(typeFunction, testedArgument);
});
}
return false;
}
function checkTypeCondition(typeFunction, testedArgument) {
switch (typeof typeFunction) {
case "function":
return typeFunction().execute(testedArgument);
case "object":
return typeFunction.execute(testedArgument);
default:
throw TypeError("Wrong arguments", typeFunction);
}
}

Sorry, the diff of this file is not supported yet

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