ecld
v1.0.2
Published
Create your configuration files in a simple and dynamic way, referencing the necessary variables according to your needs and allowing the importation of other configuration files for a better segregation.
Downloads
5
Readme
ECLD : Easy Config Language Dynamic
Create your configuration files in a simple and dynamic way, referencing the necessary variables according to your needs and allowing the importation of other configuration files for a better segregation.
Installation
npm install --save ecld
Usage
Basic
file.ecld
bar = 'Hello from bar!'
far = 'Hello from far!'
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: "Hello from bar!",
// far: "Hello from far!"
// }
Reference data
Pattern to reference data:
${context:key}
| Context | Description | | --- | ----------- | | global | Reference to all keys of the file | | local | Reference to all keys inside of specified object | | input | Reference to all data passed as input | | [alias] | Reference to import file data |
Look the example
file.ecld
bar = 'Hello from bar!'
far = 'Hello from far! and also ${global:bar}'
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: "Hello from bar!",
// far: "Hello from far! and also Hello from bar!"
// }
Import
ECLD handles two shapes of importation.
- The first one is use an import without alias like the next example
import './my_second_file'
This will do to merge all data of 'my_second_file' into the global reference of the file that is importing that file
Look the example
file_external.ecld
far = 'Hello from far!'
file.ecld
import './file_external'
bar = 'Hello from bar!'
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: "Hello from bar!",
// far: "Hello from far!"
// }
- The second one is use an import with alias like the next example
import './my_second_file' as second_file
This will do to merge all data of 'my_second_file' into the alias reference 'second_file' of the file that is importing that file and will be used with the pattern of 'alias'
Look the example
file_external.ecld
far = 'Hello from far!'
file.ecld
import './file_external' as file_external
bar = 'Hello from bar! and also ${file_external:far}'
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: "Hello from bar! and also Hello from far!",
// }
Nested Object
file.ecld
bar = {
far = 'Hello from far!'
}
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: {
// far: "Hello from far!"
// }
// }
Array
file.ecld
bar = [
{
far = 'Hello from far!'
}
]
index.js
import {load} from 'ecld';
const path = '/mydir';
const config = load(path + '/file.ecld');
// Output:
// {
// bar: [
// {
// far: "Hello from far!"
// }
// ]
// }
If you want to help this project, go to the github repository of this project