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

@keg-hub/parse-config

v2.1.0

Published

Utils to allow loading non-javascript files into a node environment

Downloads

2,851

Readme

Parse-Config

  • Helper package for parsing / loading config files with .yml and .env extensions
  • Includes simple template system for dynamically setting config values

Install

  • With yarn => yarn add @keg-hub/parse-config
  • With npm => npm install @keg-hub/parse-config

Usage

  • Require the package in your code as needed
  // Import the entire package
  const PConf = require('@keg-hub/parse-config')
  const ymlObj = await PConf.yml.load(...)
  const envObj = await PConf.env.load(...)
  const templateStr = await PConf.template.fill(...)

  // Import just sections from the package
  const { yml, env, template } = require('@keg-hub/parse-config')
  const ymlObj = await yml.load(...)
  const envObj = await env.load(...)
  const templateStr = await template.fill(...)

  // Import just specific methods from the package
  const { loadYml, loadEnv, fillTemplate } = require('@keg-hub/parse-config')
  const ymlObj = await loadYml(...)
  const envObj = await loadEnv(...)
  const templateStr = await fillTemplate(...)
  
  // Load configs based on environment from both .env and .yaml files
  const { loadConfigs } = require('@keg-hub/parse-config')
  const configObj = await loadConfigs(...)

Loading Config Files

  • The loadConfigs method can be used to automatically load config files
  • The config file names are generated from the passed in options
  • All found files are loaded, and merged together as a single config object

Priority

  • Priority is based on the name and location of the loaded file
    • The .env, then defaults.env files are always loaded first when noEnv === false, regardless of their location
    • Files loaded last, override previously loaded config values
    • For values files, both yml and yaml extentions are searched for
    • Because yaml is technically the correct extension, it will override the yml counterpart File Name
  • Given the following config options
    • env === staging
    • ymlName === values
    • name === app
    • noEnv === false
    • noYml === false
    • ymlPath === env
  • Files will be loaded in the following order,
  • First .yml files, then .yaml files, and finally .env files. See below example
    • .env then defaults.env ==> Always comes first when noEnv === false
    • values.yml then values.yaml
    • staging.yml then staging.yaml
    • app.yml then app.yaml
    • values_staging.yml then values_staging.yaml
    • values_app.yml then values_app.yaml
    • values_staging_app.yml then values_staging_app.yaml
    • values.staging.yml then values.staging.yaml
    • values.app.yml then values.app.yaml
    • values.staging.app.yml then values.staging.app.yaml
    • values-staging.yml then values-staging.yaml
    • values-app.yml then values-app.yaml
    • values-staging-app.yml then values-staging-app.yaml
    • .env.staging
    • .env.app
    • .env_app_staging
    • .env.app.staging
    • .env.app-staging
    • staging.env
    • app.env
    • app_staging.env
    • app.staging.env
    • app-staging.env

Locations

  • After the file names are generated, they are appended to the generated locations
  • Some locations are predefined, but custom locations can also be passed via the locations array config option
    • Custom locations are ALWAYS checked after the default locations
    • This allows for any files loaded from the custom locations to override the defaults

loadConfigs - Config Options

  const { loadConfigs } = require('@keg-hub/parse-config')

  const configObj = await loadConfigs({
    // Environment prefix of the config files to be loaded ( i.e. `production.env` )
    env: `local`,
    // App prefix of the config files to be loaded ( i.e. `my-app.production.env` )
    name: ``,
    // Should errors be thrown when a file exists but can't be loaded
    error: true
    // Skip loading .env files
    noEnv: false,
    // Skip loading .yaml files
    noYml: false,
    // The reference name of the values files to be loaded ( i.e. `values.local.yml` )
    ymlName: `values`,
    // Object path to return from loaded yml files
    ymlPath: `env`,
    // Format type the config should be returned as ( object | string )
    format: `object`,
    // Run template replace on the loaded config files
    fill: true,
    // Template data to fill config file with ( Requires the `fill` options value is `true`  )
    data: {...},
    // RegEx patten when running template replace
    pattern: /{{([^}]*)}}/g
    // Extra file path and directories to search for config files
    locations: [...]
    // How found configs should be merged. Must be one of overwrite | join | unique.
    mergeStrategy: `overwrite`
  })