Package Exports
- data-store
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (data-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
data-store

Store data from YAML front matter in HTML data-attributes.
Install
Install with npm:
npm i data-store --save-devUsage
var dataStore = require('data-store');This is foo.html:
---
title: Home
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
this is the body
</body>
</html>.set()
To store the YAML front matter from foo.html in data attributes:
// Read the file in as a string
var str = fs.readFileSync('foo.html');
// pass the string to data-store
var store = dataStore(str);To store the data from the front-matter in data attributes (by default data is stored on data-metadata on a script tag with the metadata id):
store.set();
console.log(store.html);Results in:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
this is the body
<script type="text/x-metadata" id="metadata" data-metadata="{\"title\":\"Home\"}"></script></body>
</html>.get()
Get the data:
store.get('metadata');id
Set a custom id:
store.set('foo');
// to get the data:
store.get('foo');extend
YAML front matter is stored by default. If an object is passed any existing front-matter will be extended.
If front-matter doesn't exist, just pass an object to store:
store.set({name: 'Jon Schlinkert'});Results in:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
this is the body
<script type="text/x-metadata" id="metadata" data-metadata="{\"name\":\"Jon Schlinkert\"}"></script></body>
</html>Or with a custom id:
store.set('foo', {name: 'Jon Schlinkert'});Results in:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
this is the body
<script type="text/x-metadata" id="foo" data-metadata="{\"name\":\"Jon Schlinkert\"}"></script></body>
</html>Author
Jon Schlinkert
Brian Woodward
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on May 01, 2014.