configchecker
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -1,2 +0,2 @@ | ||
export declare function decapitalize<T>(mixedObject: { | ||
export declare function objectDecapitalize<T>(mixedObject: { | ||
[key: string]: T; | ||
@@ -6,3 +6,3 @@ }): { | ||
}; | ||
export declare function emptyKeysAsUndefined<T>(mixedObject: { | ||
export declare function objectEmptyKeysAsUndefined<T>(mixedObject: { | ||
[key: string]: T; | ||
@@ -12,4 +12,4 @@ }, valueIsNotEmpty?: (value: T) => boolean): { | ||
}; | ||
export declare function isNotEmpty<T>(mixedObject: { | ||
export declare function objectIsNotEmpty<T>(mixedObject: { | ||
[key: string]: T | undefined; | ||
}): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function decapitalize(mixedObject) { | ||
function objectDecapitalize(mixedObject) { | ||
var decapitalizedObject = {}; | ||
@@ -12,4 +12,4 @@ for (var _i = 0, _a = Object.keys(mixedObject); _i < _a.length; _i++) { | ||
} | ||
exports.decapitalize = decapitalize; | ||
function emptyKeysAsUndefined(mixedObject, valueIsNotEmpty) { | ||
exports.objectDecapitalize = objectDecapitalize; | ||
function objectEmptyKeysAsUndefined(mixedObject, valueIsNotEmpty) { | ||
if (valueIsNotEmpty === void 0) { valueIsNotEmpty = function (value) { return !!value; }; } | ||
@@ -25,5 +25,5 @@ var purgedObject = {}; | ||
} | ||
exports.emptyKeysAsUndefined = emptyKeysAsUndefined; | ||
exports.objectEmptyKeysAsUndefined = objectEmptyKeysAsUndefined; | ||
// TODO: maybe this should be typeguard | ||
function isNotEmpty(mixedObject) { | ||
function objectIsNotEmpty(mixedObject) { | ||
for (var _i = 0, _a = Object.keys(mixedObject); _i < _a.length; _i++) { | ||
@@ -37,2 +37,2 @@ var mixedKey = _a[_i]; | ||
} | ||
exports.isNotEmpty = isNotEmpty; | ||
exports.objectIsNotEmpty = objectIsNotEmpty; |
{ | ||
"name": "configchecker", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Awesome checker of config - fully support typescript, fluent API,...", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"prettier": "prettier --config .prettierrc --write \"{src,test,.vscode}/**/*.{ts,json}\"", | ||
"prettier-watch": "onchange --initial \"**/*\" -- npm run prettier", | ||
"prettier-watch": "onchange \"{src,test,.vscode}/**/*.{ts,json}\" -- prettier --config .prettierrc --write {{changed}}", | ||
"test": "jest --config jestconfig.json", | ||
@@ -19,3 +19,4 @@ "test-watch": "jest --config jestconfig.json --watchAll", | ||
"preversion": "npm run lint", | ||
"postversion": "git push && git push --tags" | ||
"postversion": "git push && git push --tags", | ||
"documentation": "typedoc --excludePrivate --hideGenerator --mode file --theme minimal --out docs --name \"Config checker\" ./src" | ||
}, | ||
@@ -22,0 +23,0 @@ "repository": { |
# Config Checker | ||
Awesome checker of config - fully support typescript, fluent API,... | ||
A very simple and effective way to check config, before it's used in runtime with nice fluent API. | ||
@@ -13,7 +13,84 @@ # Install | ||
# Story | ||
When you use some ENV value do you really know what it contains or if it is really defined? | ||
```typescript | ||
export const { TESTING_MAIL } = process.env; | ||
``` | ||
This will be OK until your server tryis to send some email. Maybe it drop whole server or just dont do nothing and you will be figuring out why the hell server is working but it dont send any emails. | ||
I have this problem many many times. | ||
And because I am a TypeScript lover it is fully using all advantages of static typing. | ||
# Usage | ||
__TODO:__ | ||
I load the config from some environment Object: | ||
```typescript | ||
import { ConfigChecker } from '../src/classes/ConfigChecker'; | ||
const config = ConfigChecker.from(process.env); | ||
``` | ||
And then I can read variabiles from it: | ||
```typescript | ||
config.get('TESTING_MAIL').value; | ||
``` | ||
I can enforce them: | ||
```typescript | ||
config.get('TESTING_MAIL').required().value; | ||
``` | ||
I can convert them to certain types: | ||
```typescript | ||
config.get('...').number().value; | ||
config.get('...').boolean().value; | ||
config.get('...').json().value; | ||
config.get('...').list().value; | ||
config.get('...').date().value; | ||
config.get('...').url().value; | ||
``` | ||
## Full sample 1 | ||
```typescript | ||
import { ConfigChecker } from '../src/classes/ConfigChecker'; | ||
const config = ConfigChecker.from(process.env); | ||
export const PORT = config.get('PORT').number().required().value; | ||
export const TESTING_MAIL = config.get('TESTING_MAIL').value; | ||
``` | ||
## Full sample 2 | ||
This sample is working same as sample 1 but unfortunatelly it is not using full TypeScript potencial. | ||
```typescript | ||
import { ConfigChecker } from '../src/classes/ConfigChecker'; | ||
const config = ConfigChecker.from(process.env); | ||
export default { | ||
...config.get('PORT').number().required().object, | ||
...config.get('TESTING_MAIL').object | ||
} | ||
``` | ||
# Contributing | ||
I am opened to your pull requests, feedback, suggestions and donations :) . Contact to me are on my [personal page](https://www.pavolhejny.com) | ||
# Authors | ||
@@ -25,9 +102,4 @@ | ||
# Development | ||
__TODO:__ | ||
# Thanks | ||
To boilerplate was used [my-awesome-greeter](https://github.com/caki0915/my-awesome-greeter). |
16976
104