@ikilote/json2html
v0.5.0
Published
Generation of an HTML plain text from a Json structure with several setting options.
Downloads
92
Maintainers
Readme
json2html
Generation of an HTML plain text from a Json structure with several setting options.
Installation
npm i @ikilote/json2html --save
Note for Angular:
- 0.0.6 : for View Engine
- 0.1.0+ : for Ivy
Demo
Usage
Example Json2html
import { Json2html } from '@ikilote/json2html';
console.log(
new Json2html(
{
tag: 'div',
attrs: { id: 'test1', class: 'testclasse' },
body: [
'test',
{
tag: 'div',
attrs: { id: 'test2', class: 'foobar' },
body: 'test',
},
],
},
{ formatting: 'multiline' },
).toString(),
);
/*
<div id="test1"
class="testclasse">
test
<div id="test2"
class="foobar">
test
</div>
</div>
*/
Example Json2Js
{
"tag": "div",
"attrs": {
"id": "test",
"class": "testclasse",
"test": null,
"data-test1": "`value1`",
"data-test2": "'value2'",
"data-test3": "\"value3\""
}
}
import { Json2html } from '@ikilote/json2html';
console.log(new Json2html(myJson, { tabSize: 2, tadAdded: 1 }).toString());
/*
{
tag: 'div',
attrs: {
id: 'test',
class: 'testclasse',
test: null,
'data-test1': '`value1`',
'data-test2': `'value2'`,
'data-test3': '"value3"'
}
}
*/
Publishing the library
npm run build:lib
npm run publish:lib
Publishing the demo
npm run build:demo
License
This module is released under the permissive MIT license. Your contributions are always welcome.