Gathering detailed insights and metrics for front-matter
Gathering detailed insights and metrics for front-matter
Gathering detailed insights and metrics for front-matter
Gathering detailed insights and metrics for front-matter
npm install front-matter
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
676 Stars
204 Commits
76 Forks
7 Watching
14 Branches
33 Contributors
Updated on 27 Nov 2024
JavaScript (69.67%)
TypeScript (20.02%)
Makefile (10.31%)
Cumulative downloads
Total Downloads
Last day
-5%
424,742
Compared to previous day
Last week
6.4%
2,434,494
Compared to previous week
Last month
14.2%
9,897,833
Compared to previous month
Last year
124%
57,582,431
Compared to previous year
Extract meta data (front-matter) from documents.
This modules does not do any IO (file loading or reading), only extracting and parsing front matter from strings.
This concept that was originally introduced to me through the jekyll blogging system and is pretty useful where you want to be able to easily add meta-data to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". It will also extract YAML between a separator and "...".
With npm do:
npm install front-matter
So you have a file example.md
:
1--- 2title: Just hack'n 3description: Nothing to see here 4--- 5 6This is some text about some stuff that happened sometime ago
NOTE: As of front-matter@2.0.0
valid front matter is considered to have
the starting separator on the first line.
Then you can do this:
1var fs = require('fs') 2 , fm = require('front-matter') 3 4fs.readFile('./example.md', 'utf8', function(err, data){ 5 if (err) throw err 6 7 var content = fm(data) 8 9 console.log(content) 10})
And end up with an object like this:
1{ 2 attributes: { 3 title: 'Just hack\'n', 4 description: 'Nothing to see here' 5 }, 6 body: 'This is some text about some stuff that happened sometime ago', 7 bodyBegin: 6, 8 frontmatter: 'title: Just hack\'n\ndescription: Nothing to see here' 9}
1var fm = require('front-matter')
Return a content
object with two properties:
content.attributes
contains the extracted yaml attributes in json formcontent.body
contains the string contents below the yaml separatorscontent.bodyBegin
contains the line number the body contents begins atcontent.frontmatter
contains the original yaml string contentsNOTE: By default fm()
uses ys-yaml
's safeLoad
unless you set
allowUnsafe
in the options object to true.
Check if a string contains a front matter header of "---" or "= yaml =". Primarily used internally but is useful outside of the module.
Returns true
or false
1 fm.test(string) #=> true || false
front-matter is an OPEN Source Project so please help out by reporting bugs or forking and opening pull requests when possible.
All code is linted/formatted using standard style, any non-conforming code can be automatically formatted using the the fmt make task: make fmt
.
This module is awesome because of all the folks who submitted pull requests:
Copyright (c) Jason Campbell ("Author")
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/17 approved changesets -- score normalized to 4
Reason
0 commit(s) and 1 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
Score
Last Scanned on 2024-11-18
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