Gathering detailed insights and metrics for yaml-env-defaults
Gathering detailed insights and metrics for yaml-env-defaults
npm install yaml-env-defaults
Typescript
Module System
Node Version
NPM Version
76.3
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
99.3
License
TypeScript (95.65%)
JavaScript (4.35%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
195,921
Last Day
18
Last Week
18
Last Month
8,488
Last Year
117,648
10 Stars
60 Commits
2 Forks
1 Watching
12 Branches
2 Contributors
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
Publised On
14 Jul 2023
Cumulative downloads
Total Downloads
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
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
detected GitHub workflow tokens with excessive permissions
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
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
10 existing vulnerabilities detected
Details
Score
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