npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kohlmannj/jsx-to-string

v1.3.3

Published

Parse your React JSX component to string

Downloads

3

Readme

@kohlmannj/jsx-to-string

Parse your React JSX components to string

Build Status

Differences from the Original Package

This is a fork of grommet/jsx-to-string / jsx-to-string on npm. Here are the differences:

Install

npm install @kohlmannj/jsx-to-string

Usage

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
// or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

console.log(jsxToString(<Basic test1="test" />)); //outputs: <Basic test1="test" />

Defaults

  1. The default value for function is .... Use keyValueOverride for custom key values.

Options

  • useFunctionCode (boolean)

    Optional. Defaults to false. Whether or not to use the function actual source code instead of ...

    For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

let _onClickHandler = function () {
  //no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
  useFunctionCode: true
})); //outputs: <Basic onClick={function _onClickHandler() { //no-op }} />
  • functionNameOnly (boolean)

    Optional. Defaults to false. Whether prop function values should contain only the name. This flag will only be used if useFunctionCode is set to true.

    For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
render() {
  return (
    <div />
  );
}
}); //this is your react component

let _onClickHandler = function () {
//no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
  functionNameOnly: true,
  useFunctionCode: true
})); //outputs: <Basic onClick={_onClickHandler} />
  • keyValueOverride (object)

    A key-value map that overrides the value of any React props with exact match with the given key. For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

let _onClickHandler = function () {
  //no-op
}
console.log(jsxToString(<Basic onClick={_onClickHandler} />, {
  keyValueOverride: {
    onClick: '_onClickHandler'
  }
})); //outputs: <Basic onClick={_onClickHandler} />
  • ignoreProps (array)

    An array of string keys that should be ignored from the JSX string. For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

console.log(jsxToString(<Basic test1="ignore" />, {
  ignoreProps: ['test1']
})); //outputs: <Basic />
  • ignoreTags (array)

    An array of string tags that should be ignored from the JSX string. For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

console.log(jsxToString(<Basic><svg /><img /><p>I am alone</p></Basic>, {
  ignoreTags: ['svg', 'img']
})); //outputs: <Basic><p>I am alone</p></Basic>
  • shortBooleanSyntax (boolean)

Optional. Defaults to false. Whether or not to show the short or long boolean syntax.

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

console.log(jsxToString(<Basic test test2={false} test3={true}>, {
  shortBooleanSyntax: true,
})); //outputs: <Basic test test2={false} test3 />
  • displayName (string)

    A custom value to be used as the component name. For example:

import React from 'react';
import jsxToString from '@kohlmannj/jsx-to-string';
//or var jsxToString = require('@kohlmannj/jsx-to-string');

let Basic = React.createClass({
  render() {
    return (
      <div />
    );
  }
}); //this is your react component

console.log(jsxToString(<Basic test1="ignore" />, {
  displayName: 'CustomName'
})); //outputs: <CustomName />

License

MIT