Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pcrab/pconfig
https://github.com/pcrab/pconfig
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/pcrab/pconfig
- Owner: Pcrab
- License: mit
- Created: 2022-10-06T09:09:24.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T10:13:48.000Z (over 1 year ago)
- Last Synced: 2024-11-07T01:28:48.848Z (2 months ago)
- Language: TypeScript
- Size: 427 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PConfig
A simple config lib, respects XDG Base Directory settings.
## Usage
Must provide either `appName` or `basePath` to locate the config file path.
The final path is `XDG_CONFIG_HOME/[appName]` or `basePath`.Must provide either `fileName` or `fileType` to finally fine the file.
The final fileName is `fileName` or `config.[fileType]`.Also `defaultConfig` can be provided.
**file:** *XDG_CONFIG_HOME/appName/config.json*
```json
{
"test": 1234,
"testObj": {
"test1": "test2",
"testArray": [1, 2, 3, 4]
}
}
```**file:** *XDG_CONFIG_HOME/appName/testConfig.yaml*
```yaml
test: 1234
testObj:
test1: "test2"
testArray: [1, 2, 3, 4]
```**file:** *somePath/config.toml*
```toml
test = 1234
[testObj]
test1 = "test2"
testArray = [1, 2, 3, 4]
``````typescript
import readConfig from "@pcrab/pconfig";/*
{
test: 1234,
testObj: {
test1: "test2",
testArray: [1, 2, 3, 4]
}
}
*/
readConfig({appName: "appName"});
readConfig({appName: "appName", fileName: "testConfig.yaml"});/*
{
test: 1234,
testObj: {
test1: "test2",
testArray: [1, 2, 3, 4]
},
testDefault: 4321
}
*/
readConfig({
basePath: "somePath",
fileType: "toml",
defaultConfig: {testDefault: 4321}
});
```