Gathering detailed insights and metrics for require-yml
Gathering detailed insights and metrics for require-yml
Gathering detailed insights and metrics for require-yml
Gathering detailed insights and metrics for require-yml
yml-register
Hooks into require / import to load YAML files
require-yaml
require('require-yaml') lets you load YAML/YML files using require syntax. For example: var config = require('./config.yaml');
@js-x/require-yml
require('*.yml')
require-yamljs
Allows you to require *.yml files using the yamljs module
npm install require-yml
Typescript
Module System
Node Version
NPM Version
81
Supply Chain
100
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,173,542
Last Day
381
Last Week
6,184
Last Month
26,095
Last Year
224,003
MIT License
7 Stars
26 Commits
3 Forks
1 Watchers
8 Branches
5 Contributors
Updated on Jul 03, 2024
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
require-yml@2.0.0
Unpacked Size
15.07 kB
Size
5.46 kB
File Count
5
NPM Version
6.4.1
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
139.6%
381
Compared to previous day
Last Week
-3.9%
6,184
Compared to previous week
Last Month
10%
26,095
Compared to previous month
Last Year
-8.8%
224,003
Compared to previous year
It's instead of require-yaml because of this reason.
And, it can require a yml/yaml/json file/whole directory, or with iterator, or use async callback.
1npm install require-yml
2.0.0
1.x
defaults to suppresses load/parse errors, version 2.x
defaults to throw them.v1.4.x
and v2.x
let you provide your own error handlers: restore original behavior by providing your own onLoadError
as an empty function.configs directory:
1configs/ 2 |- foo/ 3 |- bar/ 4 |- a.yml 5 |- b.yaml 6 |- c.json 7 |- empty/
1const req = require('require-yml')
1const yml = req('./configs/foo/bar/a.yml') 2const yaml = req('./configs/foo/bar/b') // b.yaml 3const json = req('./configs/foo/bar/c.json') 4console.log(yml, yaml, json) 5// >> {}, {}, {}
1const all = req('./configs') 2console.log(all) 3// >> json object {"foo":{"bar":[Object Object]}
undefined
1const empty = req('./configs/empty') 2console.log(empty) 3// >> undefined
1const yml = req(['./config/default.yml', './configs/local.yml'])
/\.yml$/
- see below)1const yml = req(['./config/default', './configs/local'])
Notes:
.js
, .yml
, .yaml
, .json
, /
(dir)
All found are merged on each other, the later cascades..js
first - gives you more power allowing to start with a type that is not native to json
or safe-mode yaml
, e.g:
1//file: config/strategies/cli-banner.js 2module.export = function CliBanner() { } 3 CliBanner.prototype.text = '@TITLE' 4CliBanner.prototype.header = function(title) { return this.text.replace(/@TITLE/, title) }
1#file: config/strategies/cli-banner.yaml 2CliBanner: 3prototype: 4 text: | 5 ----------------------- 6 | @TITLE | 7 -----------------------
1const yml = req({ 2 targets: ['./config/default', './configs/local'], 3 extensions: [ '.json', '.yaml' ] 4})
./config/default.json
./config/default.yaml
./config/default/
./config/local.json
./config/local.yaml
./config/local/
1const path = require('path') 2const camelCase = require('lodash/camelCase') 3const yml = req({ 4 target: './config', 5 fileToProp: file => camelCase(path.baseName(file)) 6})
file
provided to fileToProp
is a full absolute path as it appears on your OSfileToProp(file)
returns is used as property nametargets
is a synonym for target
for readability . Each can be provided as a string or as an array of strings. If you provide both - target
is used, targets
is ignored. When it's provided as a string - it's understood as a list of files with a single-element.1const fs = require('fs') 2const jsonc = require('jsonc') 3const yml = req({ 4 targets: ['./config/default', './configs/local'], 5 loaders: [{ 6 pattern: /.jsonc?$/, //<-- this will match .json and .jsonc alike 7 load: target => jsonc.parse(fs.readFileSync(target)), 8 }]
Notes:
{ pattern: /\.(yml|yaml)$/, load: target => jsYaml.load(fs.readFileSync(resolvePath(target), 'utf8')) },
{ pattern: /\.(json|js)$/, load: target => require(resolvePath(target)) },
loaders
does not effect order of loaded files (order of extensions
does, and only between files in same directory)loaders
extensions
1const mapper = function(json) { 2 json.inject = 'everywhere' 3 return json 4} 5// v >= 2.0 6const yml2 = req({ target: './configs', mapper }) 7console.log(yml2.foo.bar.a.inject) 8// >> 'everywhere' 9 10// legacy form (supported for backward compatibility) 11const yml1 = req('./configs', mapper) 12console.log(yml1.foo.bar.a.inject) 13
1const yml = req({ 2 target: './configs', 3 mapper: function broken(json) { 4 a = b // -> throws `a is undefined` 5 }, 6 onLoadError: err => { 7 // handle your errors here 8 switch(e.CODE) { 9 ... 10 } 11 }, 12})
or use the global hook:
1req.onLoadError = function(err) { 2 // handle your errors here 3 switch(e.CODE) { 4 ... 5 } 6}
1req('./configs', null, function(yml){ 2 console.log(yml.foo.bar.a) 3}) 4// >> {}
Note: operation is pseudo async. Nothing happens in parallel, but the loading happens on next tick after your code has ran and all your declarations are made.
1npm test
Test outputs numbered test cases. Numbered test-cases can be used to filter ran tests.
1node test 15,18
will run only cases 15,18.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/24 approved changesets -- score normalized to 2
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
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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