Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

attribute-store

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attribute-store

Store template context on data attributes in static HTML, allowing metadata to be retrieved/updated post-render.

latest
Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

attribute-store NPM version

Store template context on data attributes in static HTML, allowing metadata to be retrieved/updated post-render.

Install

Install with npm:

npm i attribute-store --save-dev

Usage

var attrStore = require('attribute-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 attribute-store
var store = attrStore(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

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license

This file was generated by verb on November 17, 2014.

Keywords

attr

FAQs

Package last updated on 17 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts