Skip to content

Commit

Permalink
Merge pull request #1 from edge/feature/initial-version
Browse files Browse the repository at this point in the history
v0.1.0
  • Loading branch information
adamkdean authored Nov 26, 2021
2 parents fdcdf7f + f415b5b commit f3c7069
Show file tree
Hide file tree
Showing 11 changed files with 897 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist
/node_modules
9 changes: 9 additions & 0 deletions .eslintrc.json
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"
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist/**/*.tsbuildinfo
/node_modules
/package-lock.json
675 changes: 675 additions & 0 deletions GPL.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions LICENSE.md
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!
56 changes: 55 additions & 1 deletion README.md
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!
7 changes: 7 additions & 0 deletions dist/lib/index.d.ts
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;
}
34 changes: 34 additions & 0 deletions dist/lib/index.js
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;
36 changes: 36 additions & 0 deletions lib/index.ts
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
}
}
28 changes: 28 additions & 0 deletions package.json
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"
}
}
25 changes: 25 additions & 0 deletions tsconfig.json
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"
]
}

0 comments on commit f3c7069

Please sign in to comment.