UNPKG

@robotlegsjs/core

Version:

An architecture-based IoC framework for JavaScript/TypeScript

50 lines 2.14 kB
"use strict"; // ------------------------------------------------------------------------------ // Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved. // // NOTICE: You are permitted to use, modify, and distribute this file // in accordance with the terms of the license agreement accompanying it. // ------------------------------------------------------------------------------ Object.defineProperty(exports, "__esModule", { value: true }); exports.guardsApprove = void 0; var instantiateUnmapped_1 = require("./instantiateUnmapped"); /*============================================================================*/ /* Public Functions */ /*============================================================================*/ /** * <p>A guard can be a function, object or class.</p> * * <p>When a function is provided it is expected to return a boolean when called.</p> * * <p>When an object is provided it is expected to expose an "approve" method * that returns a boolean.</p> * * <p>When a class is provided, an instance of that class will be instantiated and tested. * If an injector is provided the instance will be created using that injector, * otherwise the instance will be created manually.</p> * * @param guards An array of guards * @param injector An optional Injector * * @return A boolean value of false if any guard returns false */ function guardsApprove(guards, injector) { for (var _i = 0, guards_1 = guards; _i < guards_1.length; _i++) { var guard = guards_1[_i]; if (typeof guard === "function" && guard.prototype.approve === undefined) { if (guard()) { continue; } return false; } if (typeof guard === "function" && guard.prototype.approve !== undefined) { guard = injector ? instantiateUnmapped_1.instantiateUnmapped(injector, guard) : new guard(); } if (!guard.approve()) { return false; } } return true; } exports.guardsApprove = guardsApprove; //# sourceMappingURL=guardsApprove.js.map