sdic
Advanced tools
Comparing version 1.6.0 to 1.7.0
const fs = require('fs'); | ||
const _path = require('path'); | ||
const _extend = require('lodash.assignin'); | ||
const _isEmpty = require('lodash.isempty'); | ||
const _isFunction = require('lodash.isfunction'); | ||
const _isPlainObject = require('lodash.isplainobject'); | ||
const _isString = require('lodash.isstring'); | ||
const _ = require('lodash'); | ||
const getParamNames = require('get-parameter-names'); | ||
@@ -45,3 +41,3 @@ const readDirR = require('fs-readdir-recursive'); | ||
let moduleName = initialName; | ||
if ('alias' in opts && !(_isString(opts.alias) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$]+$/.test(opts.alias))) { | ||
if ('alias' in opts && !(_.isString(opts.alias) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$]+$/.test(opts.alias))) { | ||
return throwError(`Invalid alias: ${opts.alias}`); | ||
@@ -104,3 +100,3 @@ } | ||
let module = require(moduleFile); | ||
if (_isPlainObject(module)) { | ||
if (_.isPlainObject(module)) { | ||
let content = fs.readFileSync(file); | ||
@@ -117,5 +113,5 @@ if (!content) { | ||
container.register( | ||
key === 'default' ? moduleName : createModuleName(key, relPath, _extend(opts, {es6: true})), | ||
key === 'default' ? moduleName : createModuleName(key, relPath, _.assignIn(opts, {es6: true})), | ||
module[key], | ||
_extend(opts, {dependencies: resolveArguments(module[key])}) | ||
_.assignIn(opts, {dependencies: resolveArguments(module[key])}) | ||
); | ||
@@ -134,2 +130,5 @@ }); | ||
let resolveArguments = (fn) => { | ||
if (_.isArray(fn.dependencies)) { | ||
return fn.dependencies; | ||
} | ||
// match argument list | ||
@@ -199,3 +198,3 @@ return getParamNames(fn).filter(String).map((v) => v.trim()) | ||
let storeInstance = _isEmpty(overrides) && factory.opts.cache; | ||
let storeInstance = _.isEmpty(overrides) && factory.opts.cache; | ||
@@ -275,3 +274,3 @@ // instance already created - return | ||
opts = _extend({cache: null, tags: []}, opts); | ||
opts = _.assignIn({cache: null, tags: []}, opts); | ||
// remove folder opts | ||
@@ -281,3 +280,3 @@ ['recursive', 'reverseName', 'ignore', 'filter'].map(opt => delete opts[opt]); | ||
// store service for later | ||
if (_isFunction(fn)) { | ||
if (_.isFunction(fn)) { | ||
factories[name] = { | ||
@@ -299,7 +298,7 @@ fn: fn, | ||
if ('prefix' in opts && !(_isString(opts.prefix) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$]+$/.test(opts.prefix))) { | ||
if ('prefix' in opts && !(_.isString(opts.prefix) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$]+$/.test(opts.prefix))) { | ||
throwError(`Invalid prefix: ${opts.prefix}`); | ||
} | ||
if ('postfix' in opts && !(_isString(opts.postfix) && /^[a-zA-Z0-9_$]+$/.test(opts.postfix))) { | ||
if ('postfix' in opts && !(_.isString(opts.postfix) && /^[a-zA-Z0-9_$]+$/.test(opts.postfix))) { | ||
throwError(`Invalid postfix: ${opts.postfix}`) | ||
@@ -334,3 +333,3 @@ } | ||
if ('alias' in opts) { | ||
if (!([null, false, undefined, ''].includes(opts.alias) || (_isString(opts.alias) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$\-]+$/.test(opts.alias)))) { | ||
if (!([null, false, undefined, ''].includes(opts.alias) || (_.isString(opts.alias) && /^[a-zA-Z_$]{1}[a-zA-Z0-9_$\-]+$/.test(opts.alias)))) { | ||
return throwError(`Invalid alias: ${opts.alias}`); | ||
@@ -337,0 +336,0 @@ } |
{ | ||
"name": "sdic", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Simple dependency injection container", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=6.0" | ||
}, | ||
"engineStrict": true, | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-register --require babel-polyfill ./test/**.test.js", | ||
"coverage": "babel-node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha ./test/**.test.js" | ||
"test": "NODE_ENV=test mocha --opts test/mocha.opts", | ||
"coverage": "NODE_ENV=test nyc mocha --opts test/mocha.opts" | ||
}, | ||
@@ -25,18 +29,16 @@ "repository": { | ||
"get-parameter-names": "^0.3.0", | ||
"lodash.assignin": "^4.2.0", | ||
"lodash.isempty": "^4.4.0", | ||
"lodash.isfunction": "^3.0.8", | ||
"lodash.isobject": "^3.0.2", | ||
"lodash.isplainobject": "^4.0.6", | ||
"lodash.isstring": "^4.0.1" | ||
"lodash": "^4.17.14" | ||
}, | ||
"devDependencies": { | ||
"babel": "^6.23.0", | ||
"babel-cli": "^6.24.0", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.0", | ||
"babel-register": "^6.24.0", | ||
"chai": "^4.0.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^4.0.0" | ||
"@babel/cli": "^7.1.5", | ||
"@babel/core": "^7.1.6", | ||
"@babel/node": "^7.0.0", | ||
"@babel/preset-env": "^7.1.6", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/register": "^7.0.0", | ||
"@babel/runtime": "^7.1.5", | ||
"babel-plugin-istanbul": "^5.1.0", | ||
"chai": "^4.2.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^14.1.1" | ||
}, | ||
@@ -49,3 +51,14 @@ "bugs": { | ||
"test": "test" | ||
}, | ||
"nyc": { | ||
"require": [ | ||
"@babel/register" | ||
], | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
], | ||
"sourceMap": false, | ||
"instrument": false | ||
} | ||
} |
@@ -7,2 +7,6 @@ # SDIC: Simple Dependency Injection Container | ||
## Prerequisites | ||
Node.js version >= 6.0 | ||
## Install | ||
@@ -122,3 +126,3 @@ ```bash | ||
module.exports = (myDb, myNextService) => { | ||
// module instance | ||
// module instance | ||
return { | ||
@@ -137,3 +141,3 @@ someMethod: () => { | ||
export default (myDb, myNextService) => { | ||
// module instance | ||
// module instance | ||
return { | ||
@@ -304,4 +308,4 @@ someMethod: () => { | ||
* rolesUsersRepositories | ||
Sounds really strange. Let's set up the loading better. The "services" folder first. It'd be cool to start the name with | ||
Sounds really strange. Let's set up the loading better. The "services" folder first. It'd be cool to start the name with | ||
the subfolder (if any), then the filename and the basedir at the end. | ||
@@ -337,3 +341,3 @@ | ||
* userRolesService | ||
We can load the "repositories" folder the same way. | ||
@@ -353,3 +357,3 @@ | ||
* docs, docs, docs | ||
Based on the idea of: https://www.npmjs.com/package/adctd | ||
Based on the idea of: https://www.npmjs.com/package/adctd |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92454
3
42
890
354
11
+ Addedlodash@^4.17.14
+ Addedlodash@4.17.21(transitive)
- Removedlodash.assignin@^4.2.0
- Removedlodash.isempty@^4.4.0
- Removedlodash.isfunction@^3.0.8
- Removedlodash.isobject@^3.0.2
- Removedlodash.isplainobject@^4.0.6
- Removedlodash.isstring@^4.0.1
- Removedlodash.assignin@4.2.0(transitive)
- Removedlodash.isempty@4.4.0(transitive)
- Removedlodash.isfunction@3.0.9(transitive)
- Removedlodash.isobject@3.0.2(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedlodash.isstring@4.0.1(transitive)