REON
REON (React Element Object Notation) is a data-interchange format inspired by React elements and JSON.
Installation
# npm npm install reon-core # yarn yarn add reon-core
Usage
First import the module:
// ES5var REON = ; // ES6;
REON.stringify()
The REON.stringify()
method converts a ReactElement to a JSON string, optionally replacing values if a replacer function is specified.
Syntax:
REON;
Parameters:
- ReactElement (required): The ReactElement to convert to a JSON string.
- replacer (optional): A function that alters the behavior of the stringification process.
Examples:
Using REON.stringify()
:
REON;// '{"type":"p","props":{"className":"classy","children":"text"}}'
Using the replacer
parameter:
REON;// '{"type":"p","props":{"className":"sophisticated","children":"text"}}'
REON.parse()
The REON.parse()
method parses a string as ReactElement, optionally transforming the value producted by parsing.
Syntax:
REON;
Parameters:
- text (required): The string to parse as ReactElement.
- reviver (optional): A function that prescribes how the value originally produced by parsing is transformed, before being returned.
Examples:
Using REON.parse()
:
REON;// React.createElement('p', { className: 'classy' }, 'text');
Using the reviver
parameter:
REON;// React.createElement('a', { href: 'http://baz.qux' }, 'link');
REON.parseObject()
The REON.parseObject()
method converts a JavaScript object into ReactElement.
Syntax:
REON;
Parameters:
- object (required): The object to convert into ReactElement.
Examples:
Using REON.parseObject()
:
REON;// React.createElement('p', { className: 'classy' }, 'text');
Testing
# npm npm testnpm run lint # yarn yarn testyarn run lint
Thanks
To all the contributors.