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

jsxon

v0.0.11

Published

JSX object notation - converts from simple javascript objects to JSX

Downloads

7

Readme

jsxon

jsx is annoying. I made this because I prefer to do things with js, and React.createElement is too much of a hassle.

what this lets you do:

  • just use js
  • no compile step
  • no hoop jumping to get your text editor to play nice (it is just js)
  • you only have to call jsxon once, when you are ready to render. Your entire application could have a single jsxon call if you wanted. You can split up your logic and build up the object you pass in however you want.

example

return jsxon({
    el: 'ul',
    defaultElement: 'li'
    children: [0,1,2,3,4].map(function(i){
        return {
            text: i
            key: "item-"+i
        }
    })
});

is equivalent to this jsx:

var listItems = function(){
  return [0,1,2,3,4].map(function(i){
    return <li key="item-{i}">{i}</li>
  })
}

return (<ul>
  {listtItems()}
</ul>)

All keys are passed on to react except the following special keys:

  • el: the element type to use (div / ul / li / etc)
  • text: key to specify text for element (instead of children)
  • children: key to specify the child nodes of an element
  • defaultType: set the default type of element to use for type (hierachical), see: defaultType

things this does that jsx doesn't do for you)

  • defaultType

You can set the default element for "here on down". See the example of lists of lists:

var lists = ['fooList', 'barList', 'bazList'];
var items = [0,1,2,3];

return jsxon({
  el: 'ol',
  defaultElement: 'li',
  children: lists.sort.map(function(list){
    return {
            el: 'ul'
      children: items.map(function(item){
                return {
                    defaultElement: 'span'
                    children: [{
                        text: list
                    },{
                        text: ' item: '
                    },{
                        text: item
                    }]
                }
            })
    }
  })
});

is equivalent to this jsx:

return (<ol>
    <li>
        <ul>
            <li>
                <span>barList</span>
                <span> item: </span>
                <span>0</span>
            </li>
            <li>
                <span>barList</span>
                <span> item: </span>
                <span>1</span>
            </li>
            <li>
                <span>barList</span>
                <span> item: </span>
                <span>2</span>
            </li>
            <li>
                <span>barList</span>
                <span> item: </span>
                <span>3</span>
            </li>
        </ul>
    </li>
    <li>
        <ul>
            <li>
                <span>bazList</span>
                <span> item: </span>
                <span>0</span>
            </li>
            <li>
                <span>bazList</span>
                <span> item: </span>
                <span>1</span>
            </li>
            <li>
                <span>bazList</span>
                <span> item: </span>
                <span>2</span>
            </li>
            <li>
                <span>bazList</span>
                <span> item: </span>
                <span>3</span>
            </li>
        </ul>
    </li>
    <li>
        <ul>
            <li>
                <span>fooList</span>
                <span> item: </span>
                <span>0</span>
            </li>
            <li>
                <span>fooList</span>
                <span> item: </span>
                <span>1</span>
            </li>
            <li>
                <span>fooList</span>
                <span> item: </span>
                <span>2</span>
            </li>
            <li>
                <span>fooList</span>
                <span> item: </span>
                <span>3</span>
            </li>
        </ul>
    </li>
</ol>)
  • className

You can optionally use an array to specify className, it will be joined for you. This can be handy, for stuff like:

classNames = [];

if(showTheThing()){
  classNames.push('show');
}
else{
  classNames.push('hide');
}

return jsxon({
  id: 'foo',
  className: classNames
});