First Commit of new way of building the Platform
This commit is contained in:
1 parent
e48cf0dae5
commit
40e60b42cc
4616 files changed
+713402
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var env = require('env-variable');
|
||||
|
||||
/**
|
||||
* Checks if a given namespace is allowed by the environment variables.
|
||||
*
|
||||
* @param {String} name namespace that should be included.
|
||||
* @param {Array} variables
|
||||
* @returns {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
module.exports = function enabled(name, variables) {
|
||||
var envy = env()
|
||||
, variable
|
||||
, i = 0;
|
||||
|
||||
variables = variables || ['diagnostics', 'debug'];
|
||||
|
||||
for (; i < variables.length; i++) {
|
||||
if ((variable = envy[variables[i]])) break;
|
||||
}
|
||||
|
||||
if (!variable) return false;
|
||||
|
||||
variables = variable.split(/[\s,]+/);
|
||||
i = 0;
|
||||
|
||||
for (; i < variables.length; i++) {
|
||||
variable = variables[i].replace('*', '.*?');
|
||||
|
||||
if ('-' === variable.charAt(0)) {
|
||||
if ((new RegExp('^'+ variable.substr(1) +'$')).test(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((new RegExp('^'+ variable +'$')).test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"enabled@1.0.2",
|
||||
"C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer"
|
||||
]
|
||||
],
|
||||
"_from": "enabled@1.0.2",
|
||||
"_id": "enabled@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=",
|
||||
"_location": "/enabled",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "enabled@1.0.2",
|
||||
"name": "enabled",
|
||||
"escapedName": "enabled",
|
||||
"rawSpec": "1.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/diagnostics"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz",
|
||||
"_spec": "1.0.2",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer",
|
||||
"author": {
|
||||
"name": "Arnout Kazemier"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bigpipe/enabled/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"env-variable": "0.0.x"
|
||||
},
|
||||
"description": "Check if a certain debug flag is enabled.",
|
||||
"devDependencies": {
|
||||
"assume": "1.3.x",
|
||||
"istanbul": "0.4.x",
|
||||
"mocha": "2.3.x",
|
||||
"pre-commit": "1.1.x"
|
||||
},
|
||||
"homepage": "https://github.com/bigpipe/enabled#readme",
|
||||
"keywords": [
|
||||
"enabled",
|
||||
"debug",
|
||||
"diagnostics",
|
||||
"flag",
|
||||
"env",
|
||||
"variable",
|
||||
"localstorage"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "enabled",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/bigpipe/enabled.git"
|
||||
},
|
||||
"scripts": {
|
||||
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js",
|
||||
"test": "mocha test.js",
|
||||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js",
|
||||
"watch": "mocha --watch test.js"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
describe('enabled', function () {
|
||||
'use strict';
|
||||
|
||||
var assume = require('assume')
|
||||
, enabled = require('./');
|
||||
|
||||
beforeEach(function () {
|
||||
process.env.DEBUG = '';
|
||||
process.env.DIAGNOSTICS = '';
|
||||
});
|
||||
|
||||
it('uses the `debug` env', function () {
|
||||
process.env.DEBUG = 'bigpipe';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.true();
|
||||
assume(enabled('false')).to.be.false();
|
||||
});
|
||||
|
||||
it('uses the `diagnostics` env', function () {
|
||||
process.env.DIAGNOSTICS = 'bigpipe';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.true();
|
||||
assume(enabled('false')).to.be.false();
|
||||
});
|
||||
|
||||
it('supports wildcards', function () {
|
||||
process.env.DEBUG = 'b*';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.true();
|
||||
assume(enabled('bro-fist')).to.be.true();
|
||||
assume(enabled('ro-fist')).to.be.false();
|
||||
});
|
||||
|
||||
it('is disabled by default', function () {
|
||||
process.env.DEBUG = '';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.false();
|
||||
|
||||
process.env.DEBUG = 'bigpipe';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.true();
|
||||
});
|
||||
|
||||
it('can ignore loggers using a -', function () {
|
||||
process.env.DEBUG = 'bigpipe,-primus,sack,-other';
|
||||
|
||||
assume(enabled('bigpipe')).to.be.true();
|
||||
assume(enabled('sack')).to.be.true();
|
||||
assume(enabled('primus')).to.be.false();
|
||||
assume(enabled('other')).to.be.false();
|
||||
assume(enabled('unknown')).to.be.false();
|
||||
});
|
||||
|
||||
it('supports multiple ranges', function () {
|
||||
process.env.DEBUG = 'bigpipe*,primus*';
|
||||
|
||||
assume(enabled('bigpipe:')).to.be.true();
|
||||
assume(enabled('bigpipes')).to.be.true();
|
||||
assume(enabled('primus:')).to.be.true();
|
||||
assume(enabled('primush')).to.be.true();
|
||||
assume(enabled('unknown')).to.be.false();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user