![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@lad-tech/config
Advanced tools
Система конфигурации для nodejs с возможностью валидации и автоматической документации
npm i @lad-tech/config --save
Обязательность полей
Значения по умолчанию
Документация параметра
Конечный тип (пример, .asBoolean()
, .asInteger()
), корректно работает с TS
Массивы через разделитель с возможностью его замены
Валидация с выводом в MD таблицу
Пример вывода ошибки:
## AnyService
| error | required | default | env | description | type |
|--------------------------------------|----------|---------|-----------|-------------------------------|-----------------------|
| Параметр обязательный для заполнения | да | | ANY_LEVEL | Задает уровень взаимодействия | enum:low,middle,hight |
Экспорт конфигурации в MD таблицу
Пример:
## Logger
| required | default | env | description | type |
|----------|---------|--------------|---------------------------------------------|-------------------------------------------------------------------|
| | false | `LOG_PRETTY` | Отображать логи в человеко понятном формате | `boolean` |
| | info | `LOG_LEVEL` | Уровень отображения логов | `enum:trace,debug,info,warn,error,fatal,silent,10,20,30,40,50,60` |
## WEB сервер
| required | default | env | description | type |
|----------|-----------|-------------|------------------|-----------|
| | 127.0.0.1 | `HTTP_HOST` | HOST WEB сервера | `url` |
| | 3000 | `HTTP_PORT` | Port WEB сервера | `integer` |
JS
const { Config } = require('@lad-tech/config');
const levelEnum = 'trace,debug,info,warn,error,fatal,silent,10,20,30,40,50,60'.split(',');
class LoggerConfig extends Config {
description = 'Logger';
constructor() {
super();
this.pretty = this.param('pretty')
.default(false)
.fromEnv('LOG_PRETTY')
.description('Отображать логи в человеко понятном формате')
.asBoolean();
this.level = this.param('level')
.default('info')
.fromEnv('LOG_LEVEL')
.description('Уровень отображения логов')
.asEnum(levelEnum);
}
}
TS
import { Config } from '@lad-tech/config';
const levelEnum = 'trace,debug,info,warn,error,fatal,silent,10,20,30,40,50,60'.split(',');
class LoggerConfig extends Config {
description = 'Logger';
pretty = this.param('pretty')
.default(false)
.fromEnv('LOG_PRETTY')
.description('Отображать логи в человеко понятном формате')
.asBoolean();
level = this.param('level')
.default('info')
.fromEnv('LOG_LEVEL')
.description('Уровень отображения логов')
.asEnum(levelEnum);
}
const config = new LoggerConfig();
// Получение значений
config.pretty; // -> false
const { pretty, level } = config;
// Переопределение
config.override('pretty', true);
config.pretty; // -> true
// Документация. Возвращает текст с таблицей описания конфигурации
const doc = config.render();
// Валидация. Возвращает текст с таблицей ошибок
const err = config.renderError();
необходимо вызвать метод класса param
с указанием имени параметра и присвоить его параметру класса
class AnyConfig extends Config {
constructor() {
super();
this.paramName = this.param('paramName').asString();
}
}
Метод param
возвращает экземпляр класса ConfigItem
метод | Описание |
---|---|
fromEnv(envName) | Имя env переменной из которой будет взято значение |
description(desc) | Описание параметра |
override(value) | Перезапись параметра указанным значением |
splitter(splitter) | Разделитель для получения массива значений |
метод | тип валидации | Описание |
---|---|---|
asString() | string | Строка |
asInteger() | integer | Целое число |
asBoolean() | boolean | Булево значение |
asUrl() | url | URL начинается с http:// или https:// убирает / на конце |
asEnum(list) | enum | Значение из списка |
asArrayString() | Массив string | Массив строк |
asArrayInteger() | Массив integer | Массив целых чисел |
asArrayBoolean() | Массив boolean | Массив булевых значений |
asArrayUrl() | Массив url | Массив ссылок |
asArrayEnum(list) | Массив enum | Массив значение из списка |
FAQs
Система конфигурации
We found that @lad-tech/config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.