New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-element-to-jsx-string

Package Overview
Dependencies
Maintainers
3
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-element-to-jsx-string - npm Package Compare versions

Comparing version

to
4.1.0

2

AnonymousStatelessComponent.js
import React from 'react';
export default function(props) {
let {children} = props; // eslint-disable-line react/prop-types
const {children} = props; // eslint-disable-line react/prop-types
return <div>{children}</div>;
}

@@ -49,2 +49,4 @@ 'use strict';

var showFunctions = _ref$showFunctions === undefined ? false : _ref$showFunctions;
var _ref$useBooleanShorth = _ref.useBooleanShorthandSyntax;
var useBooleanShorthandSyntax = _ref$useBooleanShorth === undefined ? true : _ref$useBooleanShorth;

@@ -95,3 +97,3 @@ var getDisplayName = displayName || getDefaultDisplayName;

if (attribute.value === '{true}') {
if (useBooleanShorthandSyntax && attribute.value === '{true}') {
out += '' + attribute.name;

@@ -137,6 +139,10 @@ } else {

function formatProps(props, defaultProps) {
var formatted = Object.keys(props).filter(noChildren).filter(function (key) {
return noFalse(props[key]);
});
var formatted = Object.keys(props).filter(noChildren);
if (useBooleanShorthandSyntax) {
formatted = formatted.filter(function (key) {
return noFalse(props[key]);
});
}
if (!showDefaultProps) {

@@ -143,0 +149,0 @@ formatted = formatted.filter(function (key) {

@@ -13,3 +13,3 @@ /* eslint-env mocha */

function NamedStatelessComponent(props) {
let {children} = props;
const {children} = props;
return <div>{children}</div>;

@@ -460,2 +460,14 @@ }

it('reactElementToJSXString(<TestComponent />, { useBooleanShorthandSyntax: false })', () => {
expect(
reactElementToJSXString(<TestComponent testTrue={true} testFalse={false} />, {
useBooleanShorthandSyntax: false
})
).toEqual(
`<TestComponent
testFalse={false}
testTrue={true}
/>`);
});
it('should render default props', () => {

@@ -462,0 +474,0 @@ expect(

@@ -14,3 +14,4 @@ import React from 'react';

showDefaultProps = true,
showFunctions = false
showFunctions = false,
useBooleanShorthandSyntax = true
} = {}

@@ -59,3 +60,3 @@ ) {

if (attribute.value === '{true}') {
if (useBooleanShorthandSyntax && attribute.value === '{true}') {
out += `${attribute.name}`;

@@ -107,5 +108,8 @@ } else {

.keys(props)
.filter(noChildren)
.filter(key => noFalse(props[key]));
.filter(noChildren);
if (useBooleanShorthandSyntax) {
formatted = formatted.filter(key => noFalse(props[key]));
}
if (!showDefaultProps) {

@@ -112,0 +116,0 @@ formatted = formatted.filter(key => defaultProps[key] ? defaultProps[key] !== props[key] : true);

{
"name": "react-element-to-jsx-string",
"version": "4.0.0",
"version": "4.1.0",
"description": "Turn a ReactElement into the corresponding JSX string.",

@@ -24,3 +24,3 @@ "main": "index-dist.js",

"expect": "^1.14.0",
"mocha": "^2.4.5",
"mocha": "^3.0.1",
"react": "^15.2.1"

@@ -27,0 +27,0 @@ },

@@ -20,3 +20,3 @@ # react-element-to-jsx-string

- supports nesting and deep nesting like `<div a={{b: {c: {d: <div />}}}} />`
- props: supports string, number, function (inlined as `prop={function noRefCheck() {}}`), object, ReactElement (inlined), regex, booleans (with [shorthand syntax](https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes)), ...
- props: supports string, number, function (inlined as `prop={function noRefCheck() {}}`), object, ReactElement (inlined), regex, booleans (with or without [shorthand syntax](https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes)), ...
- order props alphabetically

@@ -83,2 +83,8 @@ - sort object keys in a deterministic order (`o={{a: 1, b:2}} === o={{b:2, a:1}}`)

**options.useBooleanShorthandSyntax: boolean, default true**
If true, Boolean prop values will be omitted for [shorthand syntax](https://facebook.github.io/react/docs/jsx-in-depth.html#boolean-attributes).
If false, Boolean prop values will be explicitly output like `prop={true}` and `prop={false}`
## Test

@@ -85,0 +91,0 @@