Gathering detailed insights and metrics for yaml-front-matter
Gathering detailed insights and metrics for yaml-front-matter
Gathering detailed insights and metrics for yaml-front-matter
Gathering detailed insights and metrics for yaml-front-matter
front-matter
Extract YAML front matter from a string
gray-matter
Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML front matter by default, but also has support for YAML, JSON, TOML or Coffee Front-Matter, with options to set custom delimiters. Used by metalsmith, assemble, verb and
hexo-front-matter
Front-matter parser.
vfile-matter
vfile utility to parse the YAML front matter in a file
Parses yaml or json from the beginning of a string or file
npm install yaml-front-matter
Typescript
Module System
Node Version
NPM Version
97.7
Supply Chain
98.8
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
35,581,121
Last Day
21,035
Last Week
106,368
Last Month
460,656
Last Year
5,110,253
MIT License
194 Stars
95 Commits
17 Forks
4 Watchers
16 Branches
5 Contributors
Updated on Apr 17, 2025
Minified
Minified + Gzipped
Latest Version
4.1.1
Package Id
yaml-front-matter@4.1.1
Size
48.79 kB
NPM Version
6.14.4
Node Version
12.18.0
Published on
Dec 13, 2020
Cumulative downloads
Total Downloads
Last Day
83.1%
21,035
Compared to previous day
Last Week
0.9%
106,368
Compared to previous week
Last Month
-7.2%
460,656
Compared to previous month
Last Year
5.5%
5,110,253
Compared to previous year
Parses yaml or json at the front of a string. Places the parsed content, plus the rest of the string content, into an object literal.
This readme is for the 4.x release, which introduces breaking changes. View the changelog for more information.
This
1--- 2name: Derek Worthen 3age: 127 4contact: 5 email: email@domain.com 6 address: some location 7pets: 8 - cat 9 - dog 10 - bat 11match: !!js/regexp /pattern/gim 12run: !!js/function function() { } 13--- 14Some Other content
1var fs = require('fs'); 2var yamlFront = require('yaml-front-matter'); 3 4fs.readFile('./some/file.txt', 'utf8', function(fileContents) { 5 console.log(yamlFront.loadFront(fileContents)); 6}); 7
outputs
1{ 2 name: 'Derek Worthen', 3 age: 127, 4 contact: { email: 'email@domain.com', address: 'some location' }, 5 pets: [ 'cat', 'dog', 'bat' ], 6 match: /pattern/gim, 7 run: [Function], 8 __content: '\nSome Other Content' 9}
May also use JSON
1--- 2{ 3 "name": "Derek Worthen", 4 "age": "young", 5 "anArray": ["one","two"], 6 "subObj":{"field1": "one"} 7} 8--- 9Some content
NOTE: The
---
are required to denote the start and end of front matter. There must be a newline after the opening---
and a newline preceding the closing---
.
1$ npm install yaml-front-matter
Use the -g
flag if you plan on using the command line tool.
1$ npm install yaml-front-matter -g
1var yamlFront = require('yaml-front-matter');
The dist/yamlFront.js client script will expose the yaml-front-matter library as a global, yamlFront
. The client script for js-yaml is also required. May need to load espirma for some use cases. See js-yaml for more information.
1<script src="https://unpkg.com/js-yaml@3.10.0/dist/js-yaml.js"></script> 2<script src="yamlFront.js"></script> 3<script> 4 // parse front matter with yamlFront.loadFront(String); 5</script>
Note: yaml-front-matter is delivered as a umd package so it should work within commonjs, amd and browser (as a global) environments.
1$ npm install --dev && npm start
Then visit localhost:8080
.
Outputs build files to dist/
.
1$ npm install --dev && npm run build
1npm install --dev && npm test
1Usage: yaml-front-matter [options] <yaml-front-matter content> 2 3Options: 4 5-h, --help output usage information 6-v, --version output the version number 7-c, --content [name] set the property name for the files contents [__content] 8--pretty formats json output with spaces.
Note The cli uses
safeLoadFront
and therefore will not parse yaml containing regexps, functions or undefined values.
1# Piping content from one file, through yaml parser and into another file 2cat ./some/file.txt | yaml-front-matter > output.txt
Yaml front matter wraps js-yaml to support parsing yaml front-matter.
1var input = [ 2 '---\npost: title one\n', 3 'anArray:\n - one\n - two\n', 4 'subObject:\n prop1: cool\n prop2: two', 5 '\nreg: !!js/regexp /pattern/gim', 6 '\nfun: !!js/function function() { }\n---\n', 7 'content\nmore' 8 ].join(''); 9 10var results = yamlFront.loadFront(input); 11console.log(results);
outputs
1{ post: 'title one', 2 anArray: [ 'one', 'two' ], 3 subObject: { obj1: 'cool', obj2: 'two' }, 4 reg: /pattern/gim, 5 fun: [Function], 6 __content: '\ncontent\nmore' }
Front-matter is optional.
1yamlFront.loadFront('Hello World'); 2// => { __content: "Hello World!" }
Content is optional
1yamlFront.loadFront(''); 2// => { __content: '' }
Same api as loadFront except it does not support regexps, functions or undefined. See js-yaml for more information.
The options object supports the same options available to js-yaml and adds support for an additional key.
options.contentKeyName
: Specify the object key where to store content not parsed by yaml-front-matter. defaults to __content
.1yamlFront.loadFront('Hello World', { 2 contentKeyName: 'fileContents' 3}); 4// => { fileContents: "Hello World" }
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
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