Installations
npm install yaml-env-defaults
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
18.16.0
NPM Version
9.8.0
Score
76.3
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (95.65%)
JavaScript (4.35%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
vara855
Download Statistics
Total Downloads
195,921
Last Day
18
Last Week
18
Last Month
8,488
Last Year
117,648
GitHub Statistics
10 Stars
60 Commits
2 Forks
1 Watching
12 Branches
2 Contributors
Bundle Size
112.41 kB
Minified
38.27 kB
Minified + Gzipped
Package Meta Information
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
Publised On
14 Jul 2023
Total Downloads
Cumulative downloads
Total Downloads
195,921
Last day
0%
18
Compared to previous day
Last week
-99.2%
18
Compared to previous week
Last month
34.4%
8,488
Compared to previous month
Last year
88.3%
117,648
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Welcome to yaml-env-defaults 👋
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).
Install module for Node.js
1npm install yaml-env-defaults 2 3# or 4 5yarn add yaml-env-defaults
Usage
Import
1// ES 2import { readYamlEnvSync, readYamlEnv } from 'yaml-env-defaults'; 3 4// require 5const { readYamlEnvSync, readYamlEnv } = require('yaml-env-defaults');
Reading yaml
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
Example
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.
Tests coverage report
---------------------|---------|----------|---------|---------|-------------------
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
---------------------|---------|----------|---------|---------|-------------------
Used Dependencies:
- js-yaml@4.1.0
- lodash@4.17.21
Author
👤 Valerii Nosikov
- Github: @vara855
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 7 are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/lint.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/vara855/yaml-env-defaults/tests.yml/master?enable=pin
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint.yml:1
- Warn: no topLevel permission defined: .github/workflows/tests.yml:1
- Info: no jobLevel write permissions found
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
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.4
/10
Last Scanned on 2025-01-27
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