Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vasilevvitalii/vv-configuration
work (read and pretty in file) configuration for service
https://github.com/vasilevvitalii/vv-configuration
Last synced: about 2 months ago
JSON representation
work (read and pretty in file) configuration for service
- Host: GitHub
- URL: https://github.com/vasilevvitalii/vv-configuration
- Owner: VasilevVitalii
- License: mit
- Created: 2024-09-11T15:23:44.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-10-28T18:00:56.000Z (2 months ago)
- Last Synced: 2024-10-28T19:03:56.947Z (2 months ago)
- Language: TypeScript
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vv-configurator
Driver for storing app settings in a format similar to TOML## Features
* read setting from file
* create setting file if it does not exist
* update (pretty) setting file## License
MIT## Install
```bash
npm i vv-configuration
```
```typescript
import { GetConfVomlSync, SetConfVomlSync, TConfVoml } from 'vv-configuration'
```
## Functions
* GetConfVomlSync - sync read (and pretty update) conf file
* GetConfVoml - async read (and pretty update) conf file
* SetConfVomlSync - sync pretty update conf file
* SetConfVoml - async pretty update conf file## Example
```typescript
const fullFileName = '/path/to/test.conf'
const confVomlLayout = {
note: [
'CONFIGURATION DESCRIPTION',
'second line for description'
],
sections: [
{
name: 'section1',
note: [
'section 1',
'second line for description section 1'
],
params: [
{name: 'param1', default: 'def-section1-param1'},
{name: 'param2', default: 'def-section1-param2'},
]
},
{
name: 'section2',
note: [
'section 1'
],
params: [
{name: 'param1', default: 'def-section2-param1'},
{name: 'param2', default: 'def-section2-param2'},
]
},
{
note: [
'unnamed section'
],
params: [
{name: 'param1', default: 'def-param1'},
{name: 'param2', default: 'def-param1'},
]
}
]
} as TConfVomlconst confVoml = GetConfVomlSync({
fullFileName: fullFileName,
layout: confVomlLayout
})
if (confVoml.error) {
console.error(confVoml.error)
} else {
const someSetting = confVoml.result.find(f => f.section === 'section1' && f.param === 'param1')
if (!['def-section1-param1', 'section1-param1'].includes(someSetting.value)) {
someSetting.value = 'def-section1-param1'
if (confVoml.canUpdate) {
SetConfVomlSync({fullFileName: fullFileName, layout: confVomlLayout, conf: confVoml.result})
}
}
console.log(confVoml.result)
}
```
confVoml.result:
```json
[
{
"section": "section1",
"param": "param1",
"value": "def-section1-param1"
},
{
"section": "section1",
"param": "param2",
"value": "def-section1-param2"
},
{
"section": "section2",
"param": "param1",
"value": "def-section2-param1"
},
{
"section": "section2",
"param": "param2",
"value": "def-section2-param2"
},
{
"param": "param1",
"value": "def-param1"
},
{
"param": "param2",
"value": "def-param1"
}
]
```
file test.conf:
```
#############################################################
#############################################################
## CONFIGURATION DESCRIPTION ##
## second line for description ##
#############################################################
##########################################################################################################################
# section 1 #
# second line for description section 1 #
# default for "section1.param1" = "def-section1-param1" #
# default for "section1.param2" = "def-section1-param2" #
#############################################################
section1.param1 = def-section1-param1
section1.param2 = def-section1-param2#############################################################
# section 1 #
# default for "section2.param1" = "def-section2-param1" #
# default for "section2.param2" = "def-section2-param2" #
#############################################################
section2.param1 = def-section2-param1
section2.param2 = def-section2-param2#############################################################
# unnamed section #
# default for "param1" = "def-param1" #
# default for "param2" = "def-param1" #
#############################################################
param1 = def-param1
param2 = def-param1
```