UNPKG

@jems/di

Version:

An implementation of IoC pattern based on dependency injection that allows you to granulate and decouple your libraries or applications. Wrote using SOLID principles and a variety OOP patterns implementations.

48 lines (47 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Represents a provider, that provide the arguments for the given argumentable reference. */ var BuildInArgumentsNamesProvider = /** @class */ (function () { function BuildInArgumentsNamesProvider() { } /** * Returns the arguments names for the given argumentable reference. * @param reference Represents the reference where the arguments will be identified. * @returns The list of arguments of the given reference. */ BuildInArgumentsNamesProvider.prototype.getArgumentsNames = function (reference) { var stringObject = reference.toString(); var stringObjectLower = stringObject.toLowerCase(); var args = ''; if (stringObjectLower.startsWith('function')) { args = stringObject.match(/function\s.*?\(([^)]*)\)/)[1]; } else if (stringObjectLower.startsWith('class')) { var constructorIndex = stringObjectLower.indexOf('constructor'); if (constructorIndex >= 0) { stringObject = stringObject.substr(constructorIndex); args = stringObject.match('constructor\\s*\\((.*?)\\)')[1]; } } // Split the arguments string into an array comma delimited. return args.split(',').map(function (arg) { // Ensure no inline comments are parsed and trim the whitespace. return arg.replace(/\/\*.*\*\//, '').trim(); }).filter(function (arg) { // Ensure no undefined values are added. return arg; }); }; /** * Returns a boolean values, specifying if the given reference is argumentable. * @param reference Represents the reference that will be evaluated. * @returns If the reference is argumentable. */ BuildInArgumentsNamesProvider.prototype.isArgumetable = function (reference) { return typeof reference === 'function'; }; return BuildInArgumentsNamesProvider; }()); exports.BuildInArgumentsNamesProvider = BuildInArgumentsNamesProvider;