metarhia / metaconfiguration Goto Github PK
View Code? Open in Web Editor NEWMetarhia configuration loader ๐ง
Home Page: https://metarhia.com
License: MIT License
Metarhia configuration loader ๐ง
Home Page: https://metarhia.com
License: MIT License
Now we use:
const config = await new Config(path);
const value = config.sections.<name>.<field>;
We can't just use await new Config(path).sections
because await will be applied to sections, not to the value returned from constrictor. But if we will return promise with sections from constructor instead of promise with config instance, we can do following:
const sections = await new Config(path);
const value = sections.<name>.<field>;
We need to rename for naming consistency between metavm
, metarhia/config
, 'impress' and node.js API.
Change signature await new Config(dirPath, { sandbox })
to await new Config(dirPath, { context })
but we need to support both names sandbox
and context
for version 2.x
. In version 3.x
option sandbox
will be deprecated.
New constructor signature await new Config(path, { mode, sandbox })
Use for..of
loop instead of [].filter.map
, see: https://github.com/metarhia/config/blob/f6839f38980a6ddd63eec85bc6547214967cae3b/config.js#L25-L38
metatests
async load
to factoryasync loadFile
to async arrow functionFor example: await new Config(path, ['sectionName'])
By default all sections will be loaded.
Or with options: await new Config(path, { mode: 'debug' }, ['sectionName'])
In my opinion, there are many files in config directory, it would be great to have possibility, to describe env variables in few files.
Map by specific file names, set order priorities and highest priority for files as it was before.
It realized in node-config file-load-order
development.js
({
server: { host: '0.0.0.0' },
database: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
schema: process.env.DB_SCHEMA
},
authSecret: process.env.AUTH_SECRET,
//...
})
test.js
({
server: { host: '127.0.0.1' },
database: {
host: '127.0.0.1',
port: 5432,
schema: 'test_db'
},
authSecret: 'test_auth_secret',
//...
})
Refs: #67
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.