This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

20
node_modules/getenv/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2012-2019 Christoph Tavan <dev@tavan.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

197
node_modules/getenv/README.md generated vendored Normal file
View File

@ -0,0 +1,197 @@
# getenv
[![Build Status](https://secure.travis-ci.org/ctavan/node-getenv.png)](http://travis-ci.org/ctavan/node-getenv)
Helper to get and typecast environment variables. This is especially useful if you are building [Twelve-Factor-Apps](http://www.12factor.net/) where all configuration is stored in the environment.
## Installation
```
npm install getenv
```
TypeScript types are available from the `@types/getenv` module.
## Usage
Set environment variables:
```bash
export HTTP_HOST="localhost"
export HTTP_PORT=8080
export HTTP_START=true
export AB_TEST_RATIO=0.5
export KEYWORDS="sports,business"
export PRIMES="2,3,5,7"
```
Get and use them:
```javascript
const getenv = require('getenv');
const host = getenv('HTTP_HOST'); // same as getenv.string('HTTP_HOST');
const port = getenv.int('HTTP_PORT');
const start = getenv.bool('HTTP_START');
if (start === true) {
// const server = http.createServer();
// server.listen(port, host);
}
const abTestRatio = getenv.float('AB_TEST_RATIO');
if (Math.random() < abTestRatio) {
// test A
} else {
// test B
}
const keywords = getenv.array('KEYWORDS');
keywords.forEach(function(keyword) {
// console.log(keyword);
});
const primes = getenv.array('PRIMES', 'int');
primes.forEach(function(prime) {
// console.log(prime, typeof prime);
});
```
## Methods
All methods accept a fallback value that will be returned if the requested environment variable is not set. If the fallback value is omitted and if the requested environment variable does not exist, an exception is thrown.
### env(name, [fallback])
Alias for `env.string(name, [fallback])`.
### env.string(name, [fallback])
Return as string.
### env.int(name, [fallback])
Return as integer number.
### env.float(name, [fallback])
Return as float number.
### env.bool(name, [fallback])
Return as boolean. Only allows true/false as valid values.
### env.boolish(name, [fallback])
Return as boolean. Allows true/false/1/0 as valid values.
### env.array(name, [type], [fallback])
Split value of the environment variable at each comma and return the resulting array where each value has been typecast according to the `type` parameter. An array can be provided as `fallback`.
### env.multi({spec})
Return a list of environment variables based on a `spec`:
```javascript
const config = getenv.multi({
foo: 'FOO', // throws if FOO doesn't exist
bar: ['BAR', 'defaultval'], // set a default value
baz: ['BAZ', 'defaultval', 'string'], // parse into type
quux: ['QUUX', undefined, 'int'], // parse & throw
});
```
### env.url(name, [fallback])
Return a parsed URL as per Node's `require("url").parse`. N.B `url` doesn't validate URLs, so be sure it includes a protocol or you'll get deeply weird results.
```javascript
const serviceUrl = getenv.url('SERVICE_URL');
serviceUrl.port; // parsed port number
```
### env.disableFallbacks()
Disallows fallbacks in environments where you don't want to rely on brittle development defaults (e.g production, integration testing). For example, to disable fallbacks if we indicate production via `NODE_ENV`:
```javascript
if (process.env.NODE_ENV === 'production') {
getenv.disableFallbacks();
}
```
### env.disableErrors()
`getenv` won't throw any error. If a fallback value is provided, that will be returned, else `undefined` is returned.
```javascript
getenv.disableErrors();
console.log(getenv('RANDOM'));
// undefined
```
### env.enableErrors()
Revert the effect of `disableErrors()`.
```javascript
getenv.disableErrors();
console.log(getenv('RANDOM'));
// undefined
getenv.enableErrors();
console.log(getenv('RANDOM'));
// Error: GetEnv.Nonexistent: RANDOM does not exist and no fallback value provided.
```
## Changelog
### v1.0.0
- Drop support for Node.js older than 6.
- Modernize code.
- Add MIT License in package.json and LICENSE.md.
### v0.7.0
- Add env.disableErrors() / getenv.enableErrors() support.
### v0.6.0
- Added getenv.boolish() support.
### v0.5.0
- Add getenv.url() support.
### v0.4.0
- Add getenv.disableFallbacks() support.
### v0.3.0
- Add getenv.multi() support.
### v0.2.0
- Rename git repository
### v0.1.0
- Initial release
## Authors
- Moritz von Hase (initial author)
- Christoph Tavan <dev@tavan.de>
- Jonas Dohse <jonas@dohse.ch>
- Jan Lehnardt (@janl): `getenv.multi()` support.
- Tim Ruffles <timruffles@gmail.com>: `disableFallbacks()`, `url()`
- Ashwani Agarwal <ashwani.a@outlook.com>: `disableErrors()`, `enableErrors()`
## License
This module is licensed under the MIT license.

150
node_modules/getenv/index.js generated vendored Normal file
View File

@ -0,0 +1,150 @@
const util = require('util');
const url = require('url');
let fallbacksDisabled = false;
let throwError = true;
function _value(varName, fallback) {
const value = process.env[varName];
if (value === undefined) {
if (fallback === undefined && !throwError) {
return value;
}
if (fallback === undefined) {
throw new Error(
'GetEnv.Nonexistent: ' + varName + ' does not exist ' + 'and no fallback value provided.'
);
}
if (fallbacksDisabled) {
throw new Error(
'GetEnv.DisabledFallbacks: ' +
varName +
' relying on fallback ' +
'when fallbacks have been disabled'
);
}
return '' + fallback;
}
return value;
}
const convert = {
string: function(value) {
return '' + value;
},
int: function(value) {
const isInt = value.match(/^-?\d+$/);
if (!isInt) {
throw new Error('GetEnv.NoInteger: ' + value + ' is not an integer.');
}
return +value;
},
float: function(value) {
const isInfinity = +value === Infinity || +value === -Infinity;
if (isInfinity) {
throw new Error('GetEnv.Infinity: ' + value + ' is set to +/-Infinity.');
}
const isFloat = !(isNaN(value) || value === '');
if (!isFloat) {
throw new Error('GetEnv.NoFloat: ' + value + ' is not a number.');
}
return +value;
},
bool: function(value) {
const isBool = value === 'true' || value === 'false';
if (!isBool) {
throw new Error('GetEnv.NoBoolean: ' + value + ' is not a boolean.');
}
return value === 'true';
},
boolish: function(value) {
try {
return convert.bool(value);
} catch (err) {
const isBool = value === '1' || value === '0';
if (!isBool) {
throw new Error('GetEnv.NoBoolean: ' + value + ' is not a boolean.');
}
return value === '1';
}
},
url: url.parse,
};
function converter(type) {
return function(varName, fallback) {
if (typeof varName == 'string') {
// default
const value = _value(varName, fallback);
return convert[type](value);
} else {
// multibert!
return getenv.multi(varName);
}
};
}
const getenv = converter('string');
Object.keys(convert).forEach(function(type) {
getenv[type] = converter(type);
});
getenv.array = function array(varName, type, fallback) {
type = type || 'string';
if (Object.keys(convert).indexOf(type) === -1) {
throw new Error('GetEnv.ArrayUndefinedType: Unknown array type ' + type);
}
const value = _value(varName, fallback);
return value.split(/\s*,\s*/).map(convert[type]);
};
getenv.multi = function multi(spec) {
const result = {};
for (let key in spec) {
const value = spec[key];
if (util.isArray(value)) {
// default value & typecast
switch (value.length) {
case 1: // no default value
case 2: // no type casting
result[key] = getenv(value[0], value[1]); // dirty, when case 1: value[1] is undefined
break;
case 3: // with typecast
result[key] = getenv[value[2]](value[0], value[1]);
break;
default:
// wtf?
throw 'getenv.multi(): invalid spec';
break;
}
} else {
// value or throw
result[key] = getenv(value);
}
}
return result;
};
getenv.disableFallbacks = function() {
fallbacksDisabled = true;
};
getenv.enableFallbacks = function() {
fallbacksDisabled = false;
};
getenv.disableErrors = function() {
throwError = false;
};
getenv.enableErrors = function() {
throwError = true;
};
module.exports = getenv;

38
node_modules/getenv/package.json generated vendored Normal file
View File

@ -0,0 +1,38 @@
{
"name": "getenv",
"description": "Get and typecast environment variables.",
"author": "Christoph Tavan <dev@tavan.de>",
"contributors": [
"Moritz von Hase",
"Jonas Dohse <jonas@dohse.ch>",
"Jan Lehnardt",
"Tim Ruffles <timruffles@gmail.com>",
"Ashwani Agarwal <ashwani.a@outlook.com>"
],
"version": "1.0.0",
"license": "MIT",
"homepage": "https://github.com/ctavan/node-getenv",
"repository": {
"type": "git",
"url": "git://github.com/ctavan/node-getenv.git"
},
"main": "index.js",
"scripts": {
"prettier": "prettier --write *.{js,md} **/*.js",
"test": "bash -ec 'for F in test/*.js; do echo \"$F\": ; node $F; done;'"
},
"engines": {
"node": ">=6"
},
"dependencies": {},
"devDependencies": {
"prettier": "^1.18.2"
},
"keywords": [
"env",
"environment",
"config",
"configuration",
"12factor"
]
}