1.0.2 • Published 3 years ago

ecld v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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}

ContextDescription
globalReference to all keys of the file
localReference to all keys inside of specified object
inputReference to all data passed as input
aliasReference 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.

  1. 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!"
// }
  1. 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