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

fount

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fount - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

CHANGELOG.md

5

package.json
{
"name": "fount",
"version": "0.0.5",
"version": "0.0.6",
"description": "A source from which dependencies flow",

@@ -33,4 +33,5 @@ "main": "./src/index.js",

"gulp-mocha": "^0.5.1",
"should": "^4.0.4"
"should": "^4.0.4",
"sinon": "^1.12.1"
}
}

7

README.md

@@ -86,4 +86,9 @@ # Fount

### function
Registering a function with fount will cause it to invoke the function during resolution and return the result.
Registering a function with fount will cause it to invoke the function during resolution and return the result with two exceptions:
1. The function is a stub or some other abstraction that cannot have dependencies resolved for it
2. The function has dependencies which do not exist for fount
In these exceptional scenarios, fount will resolve the dependency with the function itself rather than calling it for you.
```javascript

@@ -90,0 +95,0 @@ fount.register( 'factory', function() { return 'a thing!' } );

var should = require( 'should' );
var when = require( 'when' );
var fount = require( '../src/index.js' );
var sinon = require( 'sinon' );

@@ -22,2 +23,38 @@ describe( 'when resolving values', function() {

describe( 'when resolving sinon.stub', function() {
var stub = sinon.stub();
var result;
before( function( done ) {
fount.register( 'aStub', stub );
fount.inject( function( aStub ) {
result = aStub;
done();
} );
} );
it( 'should resolve the stub as a function', function() {
result.should.eql( stub );
} );
} );
describe( 'when resolving a function with unresolvable dependencies', function() {
var fn = function( x, y, z ) {
return x + y + z;
};
var result;
before( function( done ) {
fount.register( 'unresolvable', fn );
fount.inject( function( unresolvable ) {
result = unresolvable( 1, 2, 3 );
done();
} );
} );
it( 'should resolve the stub as a function', function() {
result.should.eql( 6 );
} );
} );
describe( 'when resolving functions', function() {

@@ -24,0 +61,0 @@

@@ -10,5 +10,10 @@ var _ = require( 'lodash' );

function checkDependencies( fn, dependencies ) {
return ( _.isFunction( fn ) && !dependencies.length ) ?
trim( /[(]([^)]*)[)]/.exec( fn.toString() )[ 1 ].split( ',' ) ) :
dependencies;
var fnString = fn.toString();
if( /[(][^)]*[)]/.test( fnString ) ) {
return ( _.isFunction( fn ) && !dependencies.length ) ?
trim( /[(]([^)]*)[)]/.exec( fnString )[ 1 ].split( ',' ) ) :
dependencies;
} else {
return undefined;
}
}

@@ -79,2 +84,29 @@

function canResolve( containerName, dependencies, scopeName ) {
scopeName = scopeName || 'default';
return _.all( dependencies, function( key ) {
if( _.isArray( key ) ) {
var ctr = container( containerName );
var vals = [];
key.forEach( function( k ) {
var originalKey = k;
var parts = k.split( '.' );
if( parts.length > 1 ) {
ctr = container( parts[ 0 ] );
k = parts[ 1 ];
}
vals.push( ctr[ k ] );
} );
return _.all( vals );
} else {
var parts = key.split( '.' );
if( parts.length > 1 ) {
containerName = parts[ 0 ];
key = parts[ 1 ];
}
return container( containerName )[ key ];
}
} );
}
function resolve( containerName, key, scopeName ) {

@@ -122,3 +154,3 @@ scopeName = scopeName || 'default';

return function( scopeName ) {
if( _.isFunction( value ) ) {
if( _.isFunction( value ) && dependencies && canResolve( containerName, dependencies, scopeName ) ) {
var args = dependencies.map( function( key ) {

@@ -145,3 +177,3 @@ return resolve( containerName, key, scopeName );

}
else if( _.isFunction( value ) ) {
else if( _.isFunction( value ) && dependencies && canResolve( containerName, dependencies, scopeName ) ) {
var args = dependencies.map( function( key ) {

@@ -165,3 +197,3 @@ return resolve( containerName, key, scopeName );

var promise;
if( _.isFunction( value ) ) {
if( _.isFunction( value ) && dependencies && canResolve( containerName, dependencies ) ) {
var args = dependencies.map( function( key ) {

@@ -168,0 +200,0 @@ return resolve( containerName, key );

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