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
+99
@@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Gather environment variables from various locations.
|
||||
*
|
||||
* @param {Object} environment The default environment variables.
|
||||
* @returns {Object} environment.
|
||||
* @api public
|
||||
*/
|
||||
function env(environment) {
|
||||
environment = environment || {};
|
||||
|
||||
if ('object' === typeof process && 'object' === typeof process.env) {
|
||||
env.merge(environment, process.env);
|
||||
}
|
||||
|
||||
if ('undefined' !== typeof window) {
|
||||
if ('string' === window.name && window.name.length) {
|
||||
env.merge(environment, env.parse(window.name));
|
||||
}
|
||||
|
||||
if (window.localStorage) {
|
||||
try { env.merge(environment, env.parse(window.localStorage.env || window.localStorage.debug)); }
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
if (
|
||||
'object' === typeof window.location
|
||||
&& 'string' === typeof window.location.hash
|
||||
&& window.location.hash.length
|
||||
) {
|
||||
env.merge(environment, env.parse(window.location.hash.charAt(0) === '#'
|
||||
? window.location.hash.slice(1)
|
||||
: window.location.hash
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Also add lower case variants to the object for easy access.
|
||||
//
|
||||
var key, lower;
|
||||
for (key in environment) {
|
||||
lower = key.toLowerCase();
|
||||
|
||||
if (!(lower in environment)) {
|
||||
environment[lower] = environment[key];
|
||||
}
|
||||
}
|
||||
|
||||
return environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* A poor man's merge utility.
|
||||
*
|
||||
* @param {Object} base Object where the add object is merged in.
|
||||
* @param {Object} add Object that needs to be added to the base object.
|
||||
* @returns {Object} base
|
||||
* @api private
|
||||
*/
|
||||
env.merge = function merge(base, add) {
|
||||
for (var key in add) {
|
||||
if (has.call(add, key)) {
|
||||
base[key] = add[key];
|
||||
}
|
||||
}
|
||||
|
||||
return base;
|
||||
};
|
||||
|
||||
/**
|
||||
* A poor man's query string parser.
|
||||
*
|
||||
* @param {String} query The query string that needs to be parsed.
|
||||
* @returns {Object} Key value mapped query string.
|
||||
* @api private
|
||||
*/
|
||||
env.parse = function parse(query) {
|
||||
var parser = /([^=?&]+)=([^&]*)/g
|
||||
, result = {}
|
||||
, part;
|
||||
|
||||
if (!query) return result;
|
||||
|
||||
for (;
|
||||
part = parser.exec(query);
|
||||
result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
|
||||
);
|
||||
|
||||
return result.env || result;
|
||||
};
|
||||
|
||||
//
|
||||
// Expose the module
|
||||
//
|
||||
module.exports = env;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"env-variable@0.0.5",
|
||||
"C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer"
|
||||
]
|
||||
],
|
||||
"_from": "env-variable@0.0.5",
|
||||
"_id": "env-variable@0.0.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA==",
|
||||
"_location": "/env-variable",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "env-variable@0.0.5",
|
||||
"name": "env-variable",
|
||||
"escapedName": "env-variable",
|
||||
"rawSpec": "0.0.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/enabled"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz",
|
||||
"_spec": "0.0.5",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer",
|
||||
"author": {
|
||||
"name": "Arnout Kazemier"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/3rd-Eden/env-variable/issues"
|
||||
},
|
||||
"description": "Cross platform environment variables with process.env, window.name, location.hash and localStorage fallbacks",
|
||||
"devDependencies": {
|
||||
"assume": "^2.0.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^5.1.1"
|
||||
},
|
||||
"homepage": "https://github.com/3rd-Eden/env-variable",
|
||||
"keywords": [
|
||||
"browser",
|
||||
"env",
|
||||
"environment variable",
|
||||
"environment",
|
||||
"fallback",
|
||||
"location.hash",
|
||||
"process.env",
|
||||
"variable",
|
||||
"window.name"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "env-variable",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/3rd-Eden/env-variable.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": "0.0.5"
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
const assume = require('assume');
|
||||
const env = require('./');
|
||||
|
||||
describe('env-variable', function () {
|
||||
it('merges with process.env as we are running on node', function () {
|
||||
process.env.TESTING_ENVS = 'wat';
|
||||
|
||||
const data = env();
|
||||
assume(data.TESTING_ENVS).equals('wat');
|
||||
assume(data.foo).is.a('undefined');
|
||||
|
||||
const merged = env({ foo: 'bar' });
|
||||
|
||||
assume(merged.TESTING_ENVS).equals('wat');
|
||||
assume(merged.foo).equals('bar');
|
||||
});
|
||||
|
||||
it('lowercases keys', function () {
|
||||
process.env.UPPERCASE = 'does NOT touch VALUES';
|
||||
|
||||
const data = env({ FOO: 'bar' });
|
||||
|
||||
assume(data.UPPERCASE).equals('does NOT touch VALUES');
|
||||
assume(data.uppercase).equals('does NOT touch VALUES');
|
||||
assume(data.FOO).equals('bar');
|
||||
assume(data.foo).equals('bar');
|
||||
});
|
||||
|
||||
describe('#merge', function () {
|
||||
it('merges objects', function () {
|
||||
const data = {};
|
||||
|
||||
env.merge(data, { foo: 'bar' });
|
||||
assume(data).deep.equals({ foo: 'bar' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('#parse', function () {
|
||||
it('parses basic query strings', function () {
|
||||
const data = env.parse('foo=bar');
|
||||
|
||||
assume(data).is.a('object');
|
||||
assume(data).deep.equals({ foo: 'bar' });
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user