Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonml-to-react-element

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonml-to-react-element

To convert JsonML to React element.

  • 1.1.8
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jsonml-to-react-element

npm package NPM downloads Dependency Status

To convert JsonML to React Component.

Installation

npm install --save jsonml-to-react-element

Usage

Basic:

const ReactDOM = require('react-dom');
const toReactElement = require('jsonml-to-react-element');

const title = [
  'h1',
  'Hello world!',
];

ReactDOM.render(toReactElement(title), document.getElementById('content'));

With converters:

const React = require('react');
const ReactDOM = require('react-dom');
const toReactElement = require('jsonml-to-react-element');

const website = [
  'section',
  [
    'header',
    ...
  ],
  [
    'article',
    [
      'h1',
      'Hello world!',
    ],
  ],
  [
    'footer',
    ...
  ]
];

const html5to4 = [
  [
    (node) => ['section', 'header', 'article', 'footer'].indexOf(node[0]) > -1,
    (node, index) => React.createElement(
      'div',
      { key: index },
      node.slice(1).map((child) => toReactElement(child, html5to4))
    )
  ],
  ...
];

ReactDOM.render(
  toReactElement(website, html5to4),
  document.getElementById('content')
);

API

toReactElement(jsonml: Object [, converters: Array]): React.Component

To convert JsonML to React Component with converters.

converters: Array[Pair[Function, Function]]

Converters which are passed to toReactElement will concat with default converters. It works like switch sentence.

Each item in converters is a pair of functions. The first function is a prediction, and the second function is a processor which take JsonML node and return React Component.

Relative

jsonml.js A collection of JsonML tools.

Liscence

MIT

Keywords

FAQs

Package last updated on 26 Apr 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc