@vanillaes/frontmeta
v3.0.1
Published
Front-matter parser for key:value pairs
Downloads
49
Maintainers
Readme
FrontMeta is a minimalist front-matter format that uses key:value
pairs rather than YAML. This results in a parser that is optimized for both size and speed.
Features
- ECMAScript Module
- CommonJS Bundle Included
- Typescript Compatible
Imports
This package works isomorphically in browser and server-side JavaScript
Browser
Import directly from the local path or a CDN
<script type="module">
import { parse } from 'path/to/frontmeta/index.js'
</script>
The minified version can be imported from
<script type="module">
import { parse } from 'path/to/frontmeta/index.min.js'
</script>
Node
Install the package
npm install @vanillaes/frontmeta
Import using the module path
import { parse } from '@vanillaes/frontmeta'
Usage
Parse and stringify FrontMeta
FrontMeta.parse()
FrontMeta.parse(contents) : object
- contents - a string representing the document contents
Example
contents
---
key1:value1
key2:value2
---
This is the document body.
const frontmeta = // the document contents
const parsed = FrontMeta.parse(frontmeta)
console.log(parsed);
> {
> "meta": {
> "key1": "value1",
> "key2": "value2"
> },
> "body": "This is the document body."
> }
FrontMeta.stringify()
FrontMeta.stringify(document) : object
- document - The frontmeta document object
- meta - the frontmeta
key:value
data - body - the document body
- meta - the frontmeta
document
{
"meta": {
"key1": "value1",
"key2": "value2"
},
"body": "This is the document body."
}
const document = // the frontmeta document object
const frontmeta = FrontMeta.stringify(document)
console.log(frontmeta);
> ---
> key1:value1
> key2:value2
> ---
> This is the document body.
Typings
Typings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript.