Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

didi

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

didi - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

CHANGELOG.md

18

lib/annotation.js

@@ -0,5 +1,6 @@

import {
isArray,
isClass
} from './util';
export function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}

@@ -29,3 +30,8 @@ export function annotate() {

// function abc(a) { /* (((this is fine))) */}
//
// - can't reliably auto-annotate constructor; we'll match the
// first constructor(...) pattern found which may be the one
// of a nested class, too.
var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;

@@ -35,2 +41,3 @@ var FN_ARG = /\/\*([^*]*)\*\//m;

export function parse(fn) {
if (typeof fn !== 'function') {

@@ -40,3 +47,4 @@ throw new Error('Cannot annotate "' + fn + '". Expected a function!');

var match = fn.toString().match(FN_ARGS);
var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
return match[1] && match[1].split(',').map(function(arg) {

@@ -46,2 +54,2 @@ match = arg.match(FN_ARG);

}) || [];
}
}

@@ -5,6 +5,8 @@ import Module from './module';

parse as autoAnnotate,
annotate,
isArray
annotate
} from './annotation';
import { isArray } from './util';
export default function Injector(modules, parent) {

@@ -75,10 +77,3 @@ parent = parent || {

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) {
var fnDef = function(fn) {
if (typeof fn !== 'function') {

@@ -97,7 +92,28 @@ if (isArray(fn)) {

// TODO(vojta): optimize without apply
return fn.apply(context, dependencies);
return {
fn,
dependencies
};
};
var instantiate = function(Type) {
var {
dependencies,
fn
} = fnDef(Type);
return new fn(...dependencies);
};
var invoke = function(func, context) {
var {
dependencies,
fn
} = fnDef(func);
return fn.call(context, ...dependencies);
};
var createPrivateInjectorFactory = function(privateChildInjector) {

@@ -104,0 +120,0 @@ return annotate(function(key) {

{
"name": "didi",
"version": "1.0.3",
"version": "2.0.0",
"description": "Dependency Injection for JavaScript",
"main": "dist/didi.js",
"module": "lib/index.js",
"main": "dist/index.cjs.js",
"module": "dist/index.mjs",
"scripts": {
"all": "run-s lint test bundle",
"bundle": "NODE_ENV=production webpack",
"lint": "eslint 'lib/**/*.js' 'test/**/*.js'",
"bundle": "NODE_ENV=production rollup -c",
"lint": "eslint .",
"test": "mocha",

@@ -29,11 +29,13 @@ "prepare": "run-s bundle",

"babel-loader": "^7.1.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"eslint": "^4.9.0",
"eslint": "^4.17.0",
"eslint-plugin-mocha": "^4.11.0",
"mocha": "^4.0.1",
"npm-run-all": "^4.1.1",
"source-map-support": "^0.5.0",
"npm-run-all": "^4.1.2",
"rollup": "^0.55.5",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-uglify": "^3.0.0",
"source-map-support": "^0.5.3",
"webpack": "^3.7.1"

@@ -40,0 +42,0 @@ },

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