register-toml
v1.0.0
Published
Register a require hook for .toml files
Readme
register-toml
Adds a register hook to require() or import .toml files. Not meant for production, in which case it's preferred to include the .toml in the deployed bundle, for example with this Rollup.js plugin.
# config.toml
[config]
api = { hostname = "localhost", port = 3000 }
[probe]
[[probe.nodes]]
id = "api"
[[probe.nodes.replicas]]
address = "localhost:3001"
[[probe.nodes.replicas]]
address = "localhost:3002"
[[probe.nodes]]
id = "web"
[[probe.nodes.replicas]]
address = "localhost:4000"
[[probe.nodes.replicas]]
address = "localhost:4001"// index.js
require('register-toml');
// Default import
import configuration from './config.toml';
console.log(Object.keys(configuration)); // [ 'config', 'probe' ]
// Named import
import { config, probe } from './config.toml';
console.log(probe.nodes[1].replicas.length); // 2Installation
yarn add -D register-toml
ornpm install --save-dev register-toml
Usage
require('register-ts')Or for require()ing .toml in the REPL:
node -r register-toml