Gathering detailed insights and metrics for yaml-env-defaults
Gathering detailed insights and metrics for yaml-env-defaults
Gathering detailed insights and metrics for yaml-env-defaults
Gathering detailed insights and metrics for yaml-env-defaults
Read yaml file with environment variables substitution
npm install yaml-env-defaults
Typescript
Module System
Node Version
NPM Version
77.9
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
99.3
License
TypeScript (95.65%)
JavaScript (4.35%)
Total Downloads
261,263
Last Day
97
Last Week
2,499
Last Month
12,593
Last Year
141,404
MIT License
10 Stars
60 Commits
2 Forks
1 Watchers
12 Branches
2 Contributors
Updated on Nov 14, 2024
Minified
Minified + Gzipped
Latest Version
2.0.5
Package Id
yaml-env-defaults@2.0.5
Unpacked Size
16.10 kB
Size
5.33 kB
File Count
7
NPM Version
9.8.0
Node Version
18.16.0
Published on
Jul 14, 2023
Cumulative downloads
Total Downloads
Last Day
-14.2%
97
Compared to previous day
Last Week
35.7%
2,499
Compared to previous week
Last Month
-46.8%
12,593
Compared to previous month
Last Year
54.1%
141,404
Compared to previous year
Read yaml file with environment variables substitution
This is an wrapper under js-yaml library which can render environment variables values with defaults support in yml file. (like Java Spring application.yaml).
1npm install yaml-env-defaults 2 3# or 4 5yarn add yaml-env-defaults
1// ES 2import { readYamlEnvSync, readYamlEnv } from 'yaml-env-defaults'; 3 4// require 5const { readYamlEnvSync, readYamlEnv } = require('yaml-env-defaults');
1import { readYamlEnvSync, readYamlEnv } from 'yaml-env-defaults';
2
3// Read one yaml file synchronysly
4const config = readYamlEnvSync('../path/to/yaml-file.yml');
5
6// Read many yaml files synchronysly
7const joinedYamls = readYamlEnvSync(['first.yml', 'second.yml', 'third.yaml']);
8
9// Read yaml files with custom properties provider fn
10const propertiesMap = {
11 ENV_VAR_NAME: 'My value',
12 USERS_COUNT: 4
13};
14
15const getProperty = (key) => {
16 // without default value will be throwed error in case of missing
17 return propertiesMap[key] || 'Default value';
18}
19
20const config = readYamlEnvSync('../path/to/yaml-file.yml', getProperty);
21
22// Custom properties for js-yaml
23const config = readYamlEnvSync('../path/to/yaml-file.yml', undefined, {
24 jsYaml: {
25 onWarning: (yaml, e) => {
26 }
27 //...
28 }
29})
30
31 // the same for readYamlEnv as async
32 (async () => {
33 // Read one yaml file asynchronysly
34 const config = await readYamlEnv('../path/to/yaml-file.yml');
35 });
36//or
37readYamlEnv('../path/to/yaml-file.yml').then(config => config);
38
config-env.yml
1foo: 1 2bar: 'text-${ENV_VAR_MY}-text-${ENV_VAR_YOUR}-text' 3 4someFoo: 5 someBar: ['${ENV_VAR_MY}', '${ENV_VAR_YOUR}'] 6 yaml-array: 7 - ${ENV_VAR_MY} 8 - second 9 10someStrange: Thats/${ENV_VAR_MY}/${NAMESPACE:cloud-or-not}/${ENV_VAR_YOUR} 11 12escapedValue: 13 value: \$\{ENV_VAR_MY\}
JS output
1process.env.ENV_VAR_MY = 'Some value 2'; 2process.env.ENV_VAR_YOUR = 'Another Value'; 3 4const config = readYamlEnvSync(path.resolve(__dirname, 'config-env.yml')); 5// Object { 6// "bar": "text-Some value 2-text-Another Value-text", 7// "escapedValue": Object { 8// "value": "\\\\$\\\\{ENV_VAR_MY\\\\}", 9// }, 10// "foo": 1, 11// "someFoo": Object { 12// "someBar": Array [ 13// "Some value 2", 14// "Another Value", 15// ], 16// "yaml-array": Array [ 17// "Some value 2", 18// "second", 19// ], 20// }, 21// "someStrange": "Thats/Some value 2/cloud-or-not/Another Value", 22// }
More examples you can find in ./src/__fixtures__/
and ./src/__snapshots/
from tests snapshot results.
---------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------|---------|----------|---------|---------|-------------------
All files | 98.46 | 83.02 | 100 | 98.11 |
read-yaml-config.ts | 98.46 | 83.02 | 100 | 98.11 | 40
---------------------|---------|----------|---------|---------|-------------------
👤 Valerii Nosikov
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 1/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More