Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

37
my-app/node_modules/di/lib/annotation.js generated vendored Executable file
View file

@ -0,0 +1,37 @@
var annotate = function() {
var args = Array.prototype.slice.call(arguments);
var fn = args.pop();
fn.$inject = args;
return fn;
};
// Current limitations:
// - can't put into "function arg" comments
// function /* (no parenthesis like this) */ (){}
// function abc( /* xx (no parenthesis like this) */ a, b) {}
//
// Just put the comment before function or inside:
// /* (((this is fine))) */ function(a, b) {}
// function abc(a) { /* (((this is fine))) */}
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARG = /\/\*([^\*]*)\*\//m;
var parse = function(fn) {
if (typeof fn !== 'function') {
throw new Error('Can not annotate "' + fn + '". Expected a function!');
}
var match = fn.toString().match(FN_ARGS);
return match[1] && match[1].split(',').map(function(arg) {
match = arg.match(FN_ARG);
return match ? match[1].trim() : arg.trim();
}) || [];
};
exports.annotate = annotate;
exports.parse = parse;

5
my-app/node_modules/di/lib/index.js generated vendored Executable file
View file

@ -0,0 +1,5 @@
module.exports = {
annotate: require('./annotation').annotate,
Module: require('./module'),
Injector: require('./injector')
};

131
my-app/node_modules/di/lib/injector.js generated vendored Executable file
View file

@ -0,0 +1,131 @@
var Module = require('./module');
var autoAnnotate = require('./annotation').parse;
var Injector = function(modules, parent) {
parent = parent || {
get: function(name) {
currentlyResolving.push(name);
throw error('No provider for "' + name + '"!');
}
};
var currentlyResolving = [];
var providers = this._providers = Object.create(parent._providers || null);
var instances = this._instances = Object.create(null);
instances.injector = this;
var error = function(msg) {
var stack = currentlyResolving.join(' -> ');
currentlyResolving.length = 0;
return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
};
var get = function(name) {
if (!providers[name] && name.indexOf('.') !== -1) {
var parts = name.split('.');
var pivot = get(parts.shift());
while(parts.length) {
pivot = pivot[parts.shift()];
}
return pivot;
}
if (Object.hasOwnProperty.call(instances, name)) {
return instances[name];
}
if (Object.hasOwnProperty.call(providers, name)) {
if (currentlyResolving.indexOf(name) !== -1) {
currentlyResolving.push(name);
throw error('Can not resolve circular dependency!');
}
currentlyResolving.push(name);
instances[name] = providers[name][0](providers[name][1]);
currentlyResolving.pop();
return instances[name];
}
return parent.get(name);
};
var instantiate = function(Type) {
var instance = Object.create(Type.prototype);
var returned = invoke(Type, instance);
return typeof returned === 'object' ? returned : instance;
};
var invoke = function(fn, context) {
if (typeof fn !== 'function') {
throw error('Can not invoke "' + fn + '". Expected a function!');
}
var inject = fn.$inject && fn.$inject || autoAnnotate(fn);
var dependencies = inject.map(function(dep) {
return get(dep);
});
// TODO(vojta): optimize without apply
return fn.apply(context, dependencies);
};
var createChild = function(modules, providersFromParent) {
if (providersFromParent && providersFromParent.length) {
var fromParentModule = Object.create(null);
providersFromParent.forEach(function(name) {
if (!providers[name]) {
throw new Error('No provider for "' + name + '". Can not use provider from the parent!');
}
fromParentModule[name] = [providers[name][2], providers[name][1]];
});
modules.unshift(fromParentModule);
}
return new Injector(modules, this);
};
var factoryMap = {
factory: invoke,
type: instantiate,
value: function(value) {
return value;
}
};
modules.forEach(function(module) {
// TODO(vojta): handle wrong inputs (modules)
if (module instanceof Module) {
module.forEach(function(provider) {
var name = provider[0];
var type = provider[1];
var value = provider[2];
providers[name] = [factoryMap[type], value, type];
});
} else if (typeof module === 'object') {
Object.keys(module).forEach(function(name) {
var type = module[name][0];
var value = module[name][1];
providers[name] = [factoryMap[type], value, type];
});
}
});
// public API
this.get = get;
this.invoke = invoke;
this.instantiate = instantiate;
this.createChild = createChild;
};
module.exports = Injector;

24
my-app/node_modules/di/lib/module.js generated vendored Executable file
View file

@ -0,0 +1,24 @@
var Module = function() {
var providers = [];
this.factory = function(name, factory) {
providers.push([name, 'factory', factory]);
return this;
};
this.value = function(name, value) {
providers.push([name, 'value', value]);
return this;
};
this.type = function(name, type) {
providers.push([name, 'type', type]);
return this;
};
this.forEach = function(iterator) {
providers.forEach(iterator);
};
};
module.exports = Module;