-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from edge/feature/initial-version
v0.1.0
- Loading branch information
Showing
11 changed files
with
897 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"@edge/eslint-config-typescript" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/dist/**/*.tsbuildinfo | ||
/node_modules | ||
/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
### LICENSE | ||
|
||
Edge is the infrastructure of Web3. A peer-to-peer network and blockchain providing high performance decentralised web services, powered by the spare capacity all around us. | ||
|
||
Copyright notice<br> | ||
(C) 2021 Edge Network Technologies Limited [email protected]<br> | ||
All rights reserved | ||
|
||
This product is part of Edge.<br> | ||
|
||
Edge is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version ("the GPL"). | ||
|
||
**If you wish to use Edge outside the scope of the GPL, please contact us at [email protected] for details of alternative license arrangements.** | ||
|
||
**This product may be distributed alongside other components available under different licenses (which may not be GPL). See those components themselves, or the documentation accompanying them, to determine what licenses are applicable.** | ||
|
||
Edge is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
|
||
The GNU General Public License (GPL) is available at: https://www.gnu.org/licenses/gpl-3.0.en.html | ||
|
||
A copy can be found in the file GPL.md distributed with these files. | ||
|
||
This copyright notice MUST APPEAR in all copies of the product! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,56 @@ | ||
# config | ||
<img src="https://cdn.edge.network/assets/img/edge-logo-green.svg" width="200"> | ||
|
||
# Config | ||
|
||
Simple configuration management library | ||
|
||
[![npm version](https://img.shields.io/npm/v/@edge/config)](https://www.npmjs.com/package/@edge/config) [![npm downloads](https://img.shields.io/npm/dt/@edge/config)](https://www.npmjs.com/package/@edge/config) [![license](https://img.shields.io/npm/l/@edge/config)](LICENSE.md) | ||
|
||
- [config](#config) | ||
- [Usage](#usage) | ||
- [License](#license) | ||
|
||
## Usage | ||
|
||
This library provides simple configuration management, allowing defaults, type parsing, and automatic `.env` loading. | ||
|
||
```typescript | ||
import { Config } from '@edge/config' | ||
|
||
export class GlobalConfig { | ||
// Primitives | ||
static readonly httpPort = Config.getEnvNumber('HTTP_PORT', 80) | ||
static readonly logLevel = Config.getEnvString('LOG_LEVEL', 'info') | ||
static readonly reportingEnabled = Config.getEnvBoolean('REPORTING_ENABLED', true) | ||
|
||
// Arrays | ||
static readonly peers = Config.getEnvArray('PEERS', ['peer1', 'peer2']) | ||
static readonly csvLists = Config.getEnvArray('CSV_LISTS', [], '|') | ||
|
||
// Objects | ||
static readonly someObject = Config.getEnvObject('SOME_OBJECT', { useful: true, reason: 'provides good utility' }) | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Edge is the infrastructure of Web3. A peer-to-peer network and blockchain providing high performance decentralised web services, powered by the spare capacity all around us. | ||
|
||
Copyright notice | ||
(C) 2021 Edge Network Technologies Limited <[email protected]><br /> | ||
All rights reserved | ||
|
||
This product is part of Edge. | ||
Edge is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version ("the GPL"). | ||
|
||
**If you wish to use Edge outside the scope of the GPL, please contact us at [email protected] for details of alternative license arrangements.** | ||
|
||
**This product may be distributed alongside other components available under different licenses (which may not be GPL). See those components themselves, or the documentation accompanying them, to determine what licenses are applicable.** | ||
|
||
Edge is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
|
||
The GNU General Public License (GPL) is available at: https://www.gnu.org/licenses/gpl-3.0.en.html<br /> | ||
A copy can be found in the file GPL.md distributed with | ||
these files. | ||
|
||
This copyright notice MUST APPEAR in all copies of the product! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export declare class Config { | ||
protected static getEnvArray(key: string, defaultValue: string[]): string[]; | ||
protected static getEnvBoolean(key: string, defaultValue: boolean): boolean; | ||
protected static getEnvNumber(key: string, defaultValue: number): number; | ||
protected static getEnvObject(key: string, defaultValue: Record<string, unknown>): Record<string, unknown>; | ||
protected static getEnvString(key: string, defaultValue: string): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
exports.Config = void 0; | ||
var dotenv_1 = __importDefault(require("dotenv")); | ||
dotenv_1["default"].config(); | ||
var Config = (function () { | ||
function Config() { | ||
} | ||
Config.getEnvArray = function (key, defaultValue) { | ||
var value = process.env[key]; | ||
return value ? value.split(',') : defaultValue; | ||
}; | ||
Config.getEnvBoolean = function (key, defaultValue) { | ||
var value = process.env[key]; | ||
return value ? value === 'true' : defaultValue; | ||
}; | ||
Config.getEnvNumber = function (key, defaultValue) { | ||
var value = process.env[key]; | ||
return value ? Number(value) : defaultValue; | ||
}; | ||
Config.getEnvObject = function (key, defaultValue) { | ||
var value = process.env[key]; | ||
return value ? JSON.parse(value) : defaultValue; | ||
}; | ||
Config.getEnvString = function (key, defaultValue) { | ||
var value = process.env[key]; | ||
return value ? value : defaultValue; | ||
}; | ||
return Config; | ||
}()); | ||
exports.Config = Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2021 Edge Network Technologies Limited | ||
// Use of this source code is governed by a GNU GPL-style license | ||
// that can be found in the LICENSE.md file. All rights reserved. | ||
|
||
import Dotenv from 'dotenv' | ||
|
||
// Load environment variables from .env file if present | ||
Dotenv.config() | ||
|
||
// Provide helper methods to load environment variables | ||
export class Config { | ||
static getEnvArray(key: string, defaultValue: string[], delimiter = ','): string[] { | ||
const value = process.env[key] | ||
return value ? value.split(delimiter) : defaultValue | ||
} | ||
|
||
static getEnvBoolean(key: string, defaultValue: boolean): boolean { | ||
const value = process.env[key] | ||
return value ? value === 'true' : defaultValue | ||
} | ||
|
||
static getEnvNumber(key: string, defaultValue: number): number { | ||
const value = process.env[key] | ||
return value ? Number(value) : defaultValue | ||
} | ||
|
||
static getEnvObject(key: string, defaultValue: Record<string, unknown>): Record<string, unknown> { | ||
const value = process.env[key] | ||
return value ? JSON.parse(value) : defaultValue | ||
} | ||
|
||
static getEnvString(key: string, defaultValue: string): string { | ||
const value = process.env[key] | ||
return value ? value : defaultValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@edge/config", | ||
"version": "0.1.0", | ||
"description": "Simple configuration management library", | ||
"main": "dist/lib/index.js", | ||
"author": "Edge Network <[email protected]>", | ||
"contributors": [ | ||
"Adam K Dean <[email protected]>" | ||
], | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
"scripts": { | ||
"build": "tsc", | ||
"lint": "eslint --ext .ts src", | ||
"lint:fix": "eslint --fix --ext .ts src", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"devDependencies": { | ||
"@edge/eslint-config-typescript": "^0.1.1", | ||
"@types/node": "^16.11.10", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"eslint": "^7.32.0", | ||
"typescript": "^4.4.3" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^10.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"composite": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noImplicitAny": true, | ||
"outDir": "dist", | ||
"preserveConstEnums": true, | ||
"removeComments": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true | ||
}, | ||
"include": [ | ||
"lib/**/*", | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |