Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @burger-editor/frozen-patty with all npm packages installed. Try it out:

var frozenPatty = require("@burger-editor/frozen-patty")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@burger-editor/frozen-patty v0.9.0

Pure HTML to JSON converter that not use template engine.

frozen-patty

npm version Build Status Coverage Status

Pure HTML to JSON converter that not use template engine.

Install

$ npm install -D @burger-editor/frozen-patty

Usage

Extraction

import FrozenPatty from 'frozen-patty';

FrozenPatty('<div data-field="text">value</div>').toJSON(); // => { text: 'value' }
FrozenPatty('<div data-field="field-name">value</div>').toJSON(); // => { 'field-name': 'value' }
FrozenPatty('<a href="http://localhost" data-field="href:href">link</a>').toJSON(); // => { 'href': 'http://localhost' }

FrozenPatty('<div data-bge="text">value</div>', { attr: 'bge' }).toJSON(); // => { text: 'value' }

Data merge

FrozenPatty('<div data-field="text">value</div>').merge({ text: 'merged' }).toHTML() // => "<div data-field="text">merged</div>";

API

FrozenPatty (html[, options])

Extraction data from HTML.

arguments

argstyperequireddescriptions
htmlstringrequiredOriginal HTML
optionsObjectoptional

options†

optionstypedefaultdescriptions
attrstring"field"Data attribute name for specifying the node that FrozenPatty treats as a field

merge (data)

Data merge

argstyperequireddescriptions
dataObjectrequiredNew data

toJSON

Data to plain Object.

toHTML

Render to HTML as string.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free