1.1.0 • Published 4 months ago

nanoweb-config v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

NanowebConfig - Define Config

Overview

The defineConfig function processes a configuration object or an asynchronous function returning a configuration object for NanowebConfig. It ensures that the configuration meets the required structure and throws errors when invalid data is provided.

Installation

Ensure you have the necessary dependencies installed:

npm install nano-format

Usage

Using with an object

import { NANODatabase } from 'nano-format/database'
import { defineConfig, ThemeConfig } from 'nanoweb-config'
const config = {
	DIST_DIR: "./dist",
	PUBLIC_DIR: "./public",
	db: new NANODatabase(),
	theme: new ThemeConfig()
}
const validatedConfig = await defineConfig(config)
console.log(validatedConfig) // prints out the config object

Using with an async function

import { NANODatabase } from 'nano-format/database'
import { defineConfig, ThemeConfig } from 'nanoweb-config'
async function getConfig() {
	return {
		DIST_DIR: "./dist",
		PUBLIC_DIR: "./public",
		db: new NANODatabase(),
		theme: new ThemeConfig()
	}
}

const validatedConfig = await defineConfig(getConfig)
console.log(validatedConfig) // prints out the config object

Error Handling

If an invalid configuration is provided, an error is thrown:

try {
	await defineConfig("invalid config");
} catch (err) {
	console.error(err.message); // Configuration must be an object or function
}

License

This project is licensed under the ISC License.

1.1.0

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago