npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnet/config

v0.2.21

Published

The `@fnet/config` module is a utility designed to simplify the process of managing and accessing configuration files for applications. By focusing on ease of use and flexibility, it helps users retrieve configuration settings from YAML files located in d

Downloads

156

Readme

@fnet/config

The @fnet/config module is a utility designed to simplify the process of managing and accessing configuration files for applications. By focusing on ease of use and flexibility, it helps users retrieve configuration settings from YAML files located in designated directories. It caters to both single and batch processing of configuration files and allows users to work with custom environmental variables seamlessly.

How It Works

The module scans specified directories to locate YAML configuration files that match the provided name(s). Users can specify a default directory, relative paths, or even use the current working directory. Once a configuration is found, the module parses it and optionally updates the system's environmental variables based on the file's content.

Key Features

  • Directory Searching: Automatically searches in a sequence of specified directories and relative paths for configuration files.
  • YAML Parsing: Processes YAML files and extracts their data for easy access.
  • Environmental Variable Integration: Optionally injects configuration settings into the system’s environment variables.
  • Batch Processing: Supports handling multiple configuration files at once by accepting arrays of names.
  • Tag Filtering: Allows selective processing of YAML content based on specified tags.
  • Optional File Presence: Users can specify whether the absence of a configuration file should trigger an error.

Conclusion

The @fnet/config module provides a straightforward way to manage configuration files, making it easier for users to organize and access application settings. With its uncomplicated setup and useful features, it offers a practical solution for managing application configurations without unnecessary complexity.

@fnet/config Developer Guide

Overview

The @fnet/config library simplifies the process of loading and managing configuration files in your applications. It is particularly useful for environments where configurations need to be dynamic and flexible. The library allows developers to effortlessly locate configuration files across specified directories and optionally transfer configuration-defined environment variables to process.env.

Installation

To use @fnet/config in your project, you can install it via npm or yarn with the following commands:

Using npm:

npm install @fnet/config

Using yarn:

yarn add @fnet/config

Usage

The library provides a default asynchronous function designed to locate and process configuration files, handling various extensions such as .fnet, .fnet.yaml, and .fnet.yml. Below is a step-by-step guide on how to use the library.

import loadConfig from '@fnet/config';

async function loadMyConfig() {
  try {
    const config = await loadConfig({
      name: 'myConfig', // Name of the config file without extension
      dir: ['path/to/config', 'another/path'], // Directories to search
      rel: ['./.fnet/'], // Relative paths within directories
      transferEnv: true, // Transfer env variables to process.env
      optional: false, // Throws error if the file is not found
      tags: ['production'] // Filter by specific tags in the YAML file
    });

    console.log('Loaded configuration:', config);
  } catch (error) {
    console.error('Error loading configuration:', error);
  }
}

loadMyConfig();

Examples

Below are examples demonstrating typical usage scenarios for @fnet/config.

Example 1: Loading a Single Configuration File

import loadConfig from '@fnet/config';

async function loadSingleConfig() {
  const config = await loadConfig({ name: 'app-config' });
  console.log(config.data); // Outputs the parsed configuration data
}

Example 2: Loading Multiple Configuration Files

import loadConfig from '@fnet/config';

async function loadMultipleConfigs() {
  const configs = await loadConfig({
    name: ['db-config', 'api-config'], // Multiple config names
    dir: process.cwd() // Current working directory
  });
  
  configs.forEach(config => console.log(config.file, config.data));
}

Example 3: Handling Optional Configurations

import loadConfig from '@fnet/config';

async function loadOptionalConfig() {
  try {
    const config = await loadConfig({
      name: 'optional-config',
      optional: true // No error if file is not found
    });
    
    console.log('Optional configuration loaded:', config);
  } catch (e) {
    console.log('Config file is optional, proceeding without:', e.message);
  }
}

Acknowledgement

While the @fnet/config library does not require explicit acknowledgment of external libraries for basic usage, it leverages @fnet/yaml for parsing YAML files, ensuring efficient and reliable handling of configuration files.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  name:
    oneOf:
      - type: string
      - type: array
        items:
          type: string
    description: The name of the configuration or an array of names.
  dir:
    oneOf:
      - type: string
      - type: array
        items:
          type: string
    default: <current working directory>
    description: The directories to search within.
  rel:
    type: array
    items:
      type: string
    default:
      - ./.fnet/
      - ../.fnet/
      - ../../.fnet/
      - ../../../.fnet/
    description: Relative paths to consider within directories, will be normalized.
  transferEnv:
    type: boolean
    default: true
    description: Whether to transfer 'env' values from the configuration to process.env.
  optional:
    type: boolean
    default: false
    description: Whether the presence of the file is optional.
  tags:
    type: array
    items:
      type: string
    default: []
    description: An array of tags used for filtering YAML content.
required:
  - name
additionalProperties: false
description: Schema for the default exported function argument, handling
  configuration file processing.