Socket
Socket
Sign inDemoInstall

function-overloader

Package Overview
Dependencies
2
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.12.4 to 1.13.0

src/checkCondition/checkSingleCondition.js

205

dist/index.js

@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

}
})(this, function(__WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_8__) {
})(this, function(__WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_9__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -74,3 +74,3 @@ /******/ // The module cache

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 4);
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })

@@ -151,3 +151,3 @@ /************************************************************************/

var _checkCondition = __webpack_require__(10);
var _checkCondition = __webpack_require__(11);

@@ -198,2 +198,57 @@ var _checkCondition2 = _interopRequireDefault(_checkCondition);

});
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, index, conditionArguments, testedArguments);
}).find(function (conditionArgumentObject) {
return conditionArgumentObject.test();
}).execute();
}
function functionConditionArgument(conditionArgument, testedArgument, index, conditionArguments, testedArguments) {
return {
execute: function execute() {
return conditionArgument().execute(testedArgument, index, conditionArguments, testedArguments);
},
test: function test() {
return typeof conditionArgument === "function";
}
};
}
function objectConditionArgument(conditionArgument, testedArgument, index, conditionArguments, testedArguments) {
return {
execute: function execute() {
return conditionArgument.execute(testedArgument, index, conditionArguments, testedArguments);
},
test: function test() {
return (typeof conditionArgument === "undefined" ? "undefined" : _typeof(conditionArgument)) === "object";
}
};
}
function elseConditionArgument(conditionArgument) {
return {
execute: function execute() {
throw TypeError("Wrong arguments", conditionArgument);
},
test: function test() {
return true;
}
};
}
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createElseThrowAction;

@@ -226,11 +281,11 @@

/***/ }),
/* 4 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(5);
module.exports = __webpack_require__(6);
__webpack_require__(6);
module.exports = __webpack_require__(7);
/***/ }),
/* 5 */
/* 6 */
/***/ (function(module, exports) {

@@ -241,3 +296,3 @@

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

@@ -253,3 +308,3 @@

var _Overload = __webpack_require__(7);
var _Overload = __webpack_require__(8);

@@ -263,3 +318,3 @@ var _Overload2 = _interopRequireDefault(_Overload);

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

@@ -276,7 +331,7 @@

var _debug = __webpack_require__(8);
var _debug = __webpack_require__(9);
var _debug2 = _interopRequireDefault(_debug);
var _createSetAction = __webpack_require__(9);
var _createSetAction = __webpack_require__(10);

@@ -325,7 +380,11 @@ var _createSetAction2 = _interopRequireDefault(_createSetAction);

var _null = __webpack_require__(23);
var _interface = __webpack_require__(23);
var _interface2 = _interopRequireDefault(_interface);
var _null = __webpack_require__(25);
var _null2 = _interopRequireDefault(_null);
var _any = __webpack_require__(24);
var _any = __webpack_require__(26);

@@ -377,6 +436,7 @@ var _any2 = _interopRequireDefault(_any);

Overload.INSTANCE = (0, _createTypeFactory2.default)(_instance2.default);
Overload.INTERFACE = (0, _createTypeFactory2.default)(_interface2.default);
exports.default = Overload;
/***/ }),
/* 8 */
/* 9 */
/***/ (function(module, exports) {

@@ -387,3 +447,3 @@

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

@@ -407,3 +467,3 @@

var _createElseThrowAction = __webpack_require__(3);
var _createElseThrowAction = __webpack_require__(4);

@@ -442,3 +502,3 @@ var _createElseThrowAction2 = _interopRequireDefault(_createElseThrowAction);

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

@@ -454,3 +514,3 @@

var _checkTypeCondition = __webpack_require__(11);
var _checkTypeCondition = __webpack_require__(3);

@@ -472,57 +532,2 @@ var _checkTypeCondition2 = _interopRequireDefault(_checkTypeCondition);

/***/ }),
/* 11 */
/***/ (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, index, conditionArguments, testedArguments);
}).find(function (conditionArgumentObject) {
return conditionArgumentObject.test();
}).execute();
}
function functionConditionArgument(conditionArgument, testedArgument, index, conditionArguments, testedArguments) {
return {
execute: function execute() {
return conditionArgument().execute(testedArgument, index, conditionArguments, testedArguments);
},
test: function test() {
return typeof conditionArgument === "function";
}
};
}
function objectConditionArgument(conditionArgument, testedArgument, index, conditionArguments, testedArguments) {
return {
execute: function execute() {
return conditionArgument.execute(testedArgument, index, conditionArguments, testedArguments);
},
test: function test() {
return (typeof conditionArgument === "undefined" ? "undefined" : _typeof(conditionArgument)) === "object";
}
};
}
function elseConditionArgument(conditionArgument) {
return {
execute: function execute() {
throw TypeError("Wrong arguments", conditionArgument);
},
test: function test() {
return true;
}
};
}
/***/ }),
/* 12 */

@@ -547,3 +552,3 @@ /***/ (function(module, exports, __webpack_require__) {

var _createElseThrowAction = __webpack_require__(3);
var _createElseThrowAction = __webpack_require__(4);

@@ -760,2 +765,50 @@ var _createElseThrowAction2 = _interopRequireDefault(_createElseThrowAction);

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; };
var _checkSingleCondition = __webpack_require__(24);
var _checkSingleCondition2 = _interopRequireDefault(_checkSingleCondition);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (arg) {
var targetInterface = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return (typeof arg === "undefined" ? "undefined" : _typeof(arg)) === "object" && Object.keys(targetInterface).every(function (key) {
return (0, _checkSingleCondition2.default)(targetInterface[key], arg[key]);
});
};
/***/ }),
/* 24 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = checkSingleCondition;
var _checkTypeCondition = __webpack_require__(3);
var _checkTypeCondition2 = _interopRequireDefault(_checkTypeCondition);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function checkSingleCondition(conditionArgument, testedArgument) {
return (0, _checkTypeCondition2.default)(conditionArgument, testedArgument, 1, [conditionArgument], [testedArgument]);
}
/***/ }),
/* 25 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true

@@ -769,3 +822,3 @@ });

/***/ }),
/* 24 */
/* 26 */
/***/ (function(module, exports, __webpack_require__) {

@@ -772,0 +825,0 @@

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

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

@@ -157,2 +157,11 @@ # FUNCTION OVERLOADER

* **Overload.NULL** or **Overload.NULL()** for null
* **Overload.INTERFACE** or **Overload.INTERFACE(interfaceOptions)** for checking if tested object has interface properties with correct types
interfaceOptions is an object with property names and description
example of interface
```
interfaceOptions = {
someProperty: Overload.NUMBER,
otherProperty: Overload: STRING
}
```
* **Overload.INSTANCE(class)** check if argument instance of `class`

@@ -159,0 +168,0 @@

@@ -15,2 +15,3 @@ import createDebug from "debug";

import instanceCondition from "./types/instance";
import interfaceCondition from "./types/interface";
import nullCondition from "./types/null";

@@ -31,2 +32,3 @@ import anyCondition from "./types/any";

static INSTANCE = createTypeFactory(instanceCondition);
static INTERFACE = createTypeFactory(interfaceCondition);

@@ -33,0 +35,0 @@ static set(...testedArguments) {

@@ -212,2 +212,60 @@ /* eslint-disable no-new-wrappers */

});
it("return correct response when expected interface", () => {
let result = Overload.set({
propertyString: "someString",
propertyNumber: 1234,
propertyFunction: () => {}
})
.when(
Overload.INTERFACE({
propertyString: Overload.NUMBER,
propertyNumber: Overload.NUMBER,
propertyFunction: Overload.FUNCTION
})
)
.do(() => "wrong result")
.when(
Overload.INTERFACE({
propertyString: Overload.STRING,
propertyNumber: Overload.NUMBER,
propertyFunction: Overload.FUNCTION
})
)
.do(() => "correct result")
.done();
expect(result).to.be.equal("correct result");
});
it("return correct response when expected interface with deep interface", () => {
let result = Overload.set({
propertyString: "someString",
propertyNumber: 1234,
propertyFunction: () => {},
propertyObject: {
name: "someName"
}
})
.when(
Overload.INTERFACE({
propertyString: Overload.NUMBER,
propertyNumber: Overload.NUMBER,
propertyFunction: Overload.FUNCTION
})
)
.do(() => "wrong result")
.when(
Overload.INTERFACE({
propertyString: Overload.STRING,
propertyNumber: Overload.NUMBER,
propertyFunction: Overload.FUNCTION,
propertyObject: Overload.INTERFACE({
name: Overload.STRING
})
})
)
.do(() => "correct result")
.done();
expect(result).to.be.equal("correct result");
});
});

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc