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

yaml-configuration-loader

v1.0.2

Published

yaml configs loader

Downloads

15

Readme

YAML configuration loader

###Yaml configuration loader for node js

Installation


npm install yaml-configuration-loader

var loader = require('yaml-configuration-loader');

API Reference


Here is the full list of accessible methods:

Methods

###load( [name,] path )

load and parse a yaml file

Params:

  • name: (Optional) String. configuration name. if set, the configuration will be saved.
  • path: String. file path

Returns:

  • Object. Configuration content

###get( name )

retrieve a loaded configuration

Params:

  • name: String. configuration name.

Returns:

  • Object. Configuration content

###define( name, value )

define a new constant, it will be used during the configuration parsing

Params:

  • name: String. constant name.
  • value: Mixed. value.

###clear( )

clear the loaded configuration and the defined constants

Yaml Api Reference


Syntaxes

###${env:ENVIRONMENT_VARIABLE}

retrieves the value of an environment variable

Usage:

process.env.foobar = 'foobar_value';

file.yml

foo:
	bar: '${env:foobar}'

loaded configuration (json)

{
	"foo": {
		"bar": "foobar_value"
	}
}

###${const:CONSTANT_VARIABLE}

retrieves the value of a defined constant
by default only one constant is available: APP_PATH
it corresponds to the entry point of your application
it's the only constant which you can override

Usage:

var loader = require('yaml-configuration-loader');
loader.define('foobar','foobar_value');

file.yml

foobar: ${const:APP_PATH}
foo:
	bar: '${const:foobar}'

loaded configuration (json)

{
	"foobar": "foo/bar/app.js",
	"foo": {
		"bar": "foobar_value"
	}
}

###${local:LOCAL_VARIABLE}

retrieves the value of a property from the current configuration

Usage

file.yml

foo:
	foobar : 'foobar_value'
	bar: '${local:foo.foobar}'

loaded configuration (json)

{
	"foo": {
		"foobar": "foobar_value",
		"bar": "foobar_value"
	}
}

###${config:CONFIGURATION_NAME:CONFIGURATION_VARIABLE}

retrieves the value of a defined configuration

Usage:

var loader = require('yaml-configuration-loader');
loader.load('foobar_conf', 'xxx/xxx.yml')

xxx.yml

foo:
	bar: 'bar'

file.yml

foo:
	bar: '${config:foobar_conf:foo.bar}'

loaded configuration (json)

{
	"foo": {
		"bar": "bar"
	}
}

you can also add a default value to your dynamic fields with the pipe syntax
by default the library will transform the given value into the most relevant type ${const:foo|12} => "foo": 12, ${const:foo|bar} => "foo": "bar" you can override this behaviour by adding quotes around the value, the parser will consider the value as a string. ${const:foo|'12'} => "foo": "12"

source.yml

foo: '${const:foobar|\'hello\'}'
bar: '${const:foobar|"world"}'
foobar: '${env:foobar|"some \"string\""}'
barfoo: '${const:foobar|1337}'
barfoobar: '${config:foobar|"1024"}'

loaded configuration (json)

{
	"foo": "hello",
	"bar": "world",
	"foobar": "some \"string\"",
	"barfoo": 1337,
	"barfoobar": "1024"
}

Configuration imports

Yaml-config-loader provides an importing system
You simply need to add an import statement and add some files to import
each files are described by two properties

  • source: String. file path
  • if: (Optional) Object. conditions { 'field (dynamic of not)' : 'value to check' }
    you can use all syntaxes above presented except the ${local:...}
imports:
    - { source: 'dev/config.yml', if: { '${env:envname}': 'dev' } }

Usage:

imports:
    - { source: 'dev/config.yml', if: { '${env:envname}': 'dev' } }

foo: 'bar'

All syntaxes of js-yaml are available


Modify and build


npm install

Build command: grunt es6 It will create js files from the es6 sources.

Unit tests: grunt unit

###Credits

This library is based on the awesome js-yaml parser.