Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
babel-plugin-jsx-to-object
Advanced tools
Transform JSX into opinionated JSON Objects.
All React conventions of JSX are support, this includes:
npm install --save-dev babel-plugin-jsx-to-object
Add to your.babelrc
config
{
"plugins": [ "babel-plugin-jsx-to-object" ]
}
The following JSX:
(<h1 class="title">Hello World</h1>);
Returns:
({
extends: null,
type: 'h1',
attributes: { class: 'title' },
children: [ 'hello world' ]
});
The following JSX (with Declared Nodes):
const UL = <ul />;
const LI = <li />;
(<UL>
<LI>Learn JSX</LI>
<LI>Write effiecient UI Libraries</LI>
<LI>Profit</LI>
</UL>);
Returns:
const UL = {
extends: null,
type: 'ul',
attributes: null,
children: null
};
const LI = {
extends: null,
type: 'li',
attributes: null,
children: null
};
({
extends: UL,
type: null,
attributes: null,
children: [
{
extends: LI,
type: null,
attributes: null,
children: [ 'Learn JSX' ]
},
{
extends: LI,
type: null,
attributes: null,
children: [ 'Write efficient UI Libraries' ]
},
{
extends: LI,
type: null,
attributes: null,
children: [ 'Profit' ]
}
]
})
All the objects keys can be overidden
The following JSX:
import jsxTransform from 'babel-plugin-jsx-to-object';
const OPTIONS = {
extends: 'elementExtension',
type: 'elementName',
attributes: 'args',
children: 'kids'
};
transform('(<h1 class="title">Hello World</h1>);', { plugins: [ [jsxTransform, OPTIONS] ] })
Becomes:
({
elementExtension: null,
elementName: 'h1',
args: { class: 'title' },
kids: [ 'hello world' ]
});
FAQs
Transform JSX into opinionated JSON Objects
We found that babel-plugin-jsx-to-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.