Installations
npm install yaml-reader
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
20.3.0
NPM Version
9.6.7
Score
74.2
Supply Chain
100
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
123,598
Last Day
378
Last Week
2,074
Last Month
6,625
Last Year
61,922
GitHub Statistics
1 Stars
45 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
173.80 kB
Minified
42.13 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.4
Package Id
yaml-reader@1.0.4
Unpacked Size
25.88 kB
Size
5.05 kB
File Count
14
NPM Version
9.6.7
Node Version
20.3.0
Publised On
13 Jun 2023
Total Downloads
Cumulative downloads
Total Downloads
123,598
Last day
57.5%
378
Compared to previous day
Last week
36.8%
2,074
Compared to previous week
Last month
-3.3%
6,625
Compared to previous month
Last year
134.3%
61,922
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
3
YAML Reader
This is a lightweight reader of yaml files. It's only purpose is to read yaml files to use its attributes in a node app. Therefore it keeps simple and its dependencies low.
The asynchronous read provides promise based and callback based support, thus you can choose the style you like better.
Notes
yaml-reader is written in ECMA 6 (Node version 8.11.1). Be sure your node version can handle this or use babel for older node versions. No guarantee that everything works fine when using babel.
Installation
npm install --save yaml-reader
Usage
yaml-reader resolves the path from your project root onwards, i.e. lets assume the project structure given below.
Then you will call yamlReader.read('configs/app-config.yml')
wherever you want to read the yaml file. Thus the call
will look the same in both bin/app.js
and some/deep/project/path/someService.js
.
+-- package.json
+-- README.md
+-- bin
+---- app.js
+-- some
+---- deep
+------ project
+-------- path
+---------- someService.js
+---- ...
+-- configs
+---- app-config.yml
Synchronous read
Read a yaml file synchronously. This is like requiring a json config file via require()
:
const config = require('yaml-reader').read('path/from/project/root/to/yml.yml');
Asynchronous read
You can also read a yaml asynchronously. The result will be returned as a Promise
or, if
a callback function is provided, with a callback.
Promise based:
const yamlReader = require('yaml-reader');
yamlReader.readAsync('path/from/project/root/to/yml.yml')
.then((config) => {
...
})
.catch((err) => {
...
})
Callback based:
const yamlReader = require('yaml-reader');
// without options, thus null as 2nd arg
yamlReader.readAsync('path/from/project/root/to/yml.yml', null, (err, config) => {
if (err) {
...
}
else {
...
}
})
In all cases you can pass in the encoding of the file with an option object. If this is not passed, utf8 will be used by default.
const options = {
encoding: yamlReader.constants.ENCODING.UTF_16_LE
};
const config = require('yaml-reader').read('path/from/project/root/to/yml.yml', options);
// or async
yamlReader.readAsync('path/from/project/root/yml.yml', options, (err, config) => {
...
}
yamlReader.readAsync('path/from/project/root/yml.yml', options)
.then((config) => {
...
})
API
yamlReader.read(file [, options])
yamlReader.readYaml(file [, options])
Read a yaml file synchronously .
- file <string> : The path to the yaml file to read. Resolves from project root onwards. Read "Usage" section to see how it is resolved if unclear
- options <Object | null> : Options parsed to the reader
- options.encoding <string | null>: The encoding of the yaml file. Is 'utf-8' by default.
You can use
yaml-reader.constants.ENCODING
for supported encodings.
- options.encoding <string | null>: The encoding of the yaml file. Is 'utf-8' by default.
You can use
const config = require('yaml-reader').read('path/from/project/root/to/yml.yml');
Or with encoding specified:
const options = {
encoding: yamlReader.constants.ENCODING.UTF_8
};
const config = require('yaml-reader').read('path/from/project/root/to/yml.yml', options);
yamlReader.readAsync(file [, options, callback])
yamlReader.readYamlAsync(file [, options, callback])
Read a yaml file asynchronously. The yaml attributes will be returned with a Promise.
- file <string> : The path to the yaml file to read. Resolves from project root onwards. Read "Usage" section to see how it is resolved if unclear
- options <Object | null> : Options parsed to the reader
- options.encoding <string | null>: The encoding of the yaml file. Is 'utf-8' by default.
You can use
yaml-reader.constants.ENCODING
for supported encodings.
- options.encoding <string | null>: The encoding of the yaml file. Is 'utf-8' by default.
You can use
- callback <function | null> : An optional callback. If this is null the reader assumes you use Promises instead. So take care to use the promise syntax if you do not provide a callback.
The config is either returned as a Promise<Object>.resolve if the file was readable or rejected otherwise, or with the callback if invoked with a callback.
const yamlReader = require('yaml-reader');
const options = { ... }
//
// awaiting promises
//
yamlReader.readAsync('path/from/project/root/to/yml.yml', options)
.then((config) => {
// access properties of your yaml
// console.log(config.myProperty)
})
.catch((err) => {
// handle errors (like FileNotFoundError)
})
//
// or with callback
//
yamlReader.readAsync('path/from/project/root/to/yml.yml', options, (err, config) => {
...
}
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
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
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
Reason
Found 0/15 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
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Score
2.8
/10
Last Scanned on 2025-02-03
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 MoreOther packages similar to yaml-reader
@static-pages/yaml-reader
YAML reader for static pages.
nci-yaml-reader
YAML config files reader for nci
awesome-yaml-reader
Awesome minimal wrapper around js-yaml for directly reading in YAML files
@yaml-js/reader
This package provides a simple and flexible utility for reading YAML files in both TypeScript and JavaScript projects