0.2.1 • Published 2 years ago

dynamo-config v0.2.1

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

Dynamo

Dynamo is a useful configuration library for Deno & Node applications, built for use with TypeScript.

Usage

Using Dynamo is very simple. It is available from both NPM (dynamo-config), and deno.land/x (dynamo).

import { Dynamo } from "dynamo-config";

// You can also use a type alias union-ed with Dynamo.Config
// if you wish.
interface ApplicationConfig extends Dynamo.Config {
	verbose: boolean;
	port?: number;
	hostname?: string;
	credentials: {
		username: string;
		password: string;
	};
}

// We can pass defaults like so.
const defaults: Partial<ApplicationConfig> = {
	port: 8080,
	hostname: "localhost",
};

const config = await Dynamo.create<ApplicationConfig>({
	file: "./config.yml",
	defaults,
});

console.log(config.port);

// Reload can be called to reload the config from the filesystem.
await config.reload();
import * as Dynamo from "https://deno.land/x/dynamo/mod.ts";

// You can also use a type alias union-ed with Dynamo.Config
// if you wish.
interface ApplicationConfig extends Dynamo.Config {
	verbose: boolean;
	port?: number;
	hostname?: string;
	credentials: {
		username: string;
		password: string;
	};
}

// We can pass defaults like so.
const defaults: Partial<ApplicationConfig> = {
	port: 8080,
	hostname: "localhost",
};

const config = await Dynamo.create<ApplicationConfig>({
	file: "./config.yml",
	defaults,
});

console.log(config.port);

// Reload can be called to reload the config from the filesystem.
await config.reload();

Formats

By default, Dynamo uses YAML for configuration, but it is designed to be extendable. The create method takes an optional parser parameter with the type (content: string) => any. This allows you to use any format you can parse. Dynamo includes extra parsers for different formats in the parsers directory. For example, to use JSON:

import { json } from "https://deno.land/x/dynamo/parsers/json.ts";

const config = await Dynamo.create<ApplicationConfig>({
	file: "./config.json",
	parser: json,
});

To see the full list of parsers, see the parsers directory.

Support

For support, open an issue, or contact me on Discord.

License

Dynamo is licensed under the MIT license.