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

tersus-jsx.macro

v0.1.3

Published

This Babel-Macro provides useful props for making a better and neater JSX. These props are transformed into appropriate JSX expressions for you by Babel-Macro, so that people can just define props and forget about formulating unintuitive JSX expression, l

Downloads

229

Readme

Tersus JSX Macro

Missing the good old days of AngularJS that you can do loops simply with "ng-repeat", as oppose to ugly mix of elements and expressions in JSX while using React?

This Babel-Macro provides useful props for making a better and neater JSX. These props are transformed into appropriate JSX expressions for you by Babel-Macro, so that people can just define props and forget about formulating unintuitive JSX expression, like what we used to do in AngularJS. The current version supports:

  • if statement (tj-if) simulating ng-if
  • map function (tj-for) simulating ng-repeat/ng-for

This macro is made so that people can just define props and forget about the complicated JSX expression.

tj-if Usage (similar to ng-if)

Simply attach an expression to tj-if prop.

import tersus from 'tersus-jsx.macro';

class App extends Component {
  const a = 0;
  render() {
    return tersus(
      <>
        <div tj-if={a === 0}>Make neater JSX</div>
      </>
    )
  }
}

is equivalent to

class App extends Component {
  const a = 0;
  render() {
    return (
      <>
        {a === 0 && <><div>Make neater JSX</div></>}
      </>
    )
  }
}

tj-for Usage (similar to ng-repeat/ng-for)

Simply attach an array to tj-for, which formulates ES6 JavaScript map. The "--value" string will be translated into the actual value variable in map. The "--index" string will be translated into the index. If the array contains nested objects, you can define the string "--value.name" for grabbing the value in the object.

import tersus from 'tersus-jsx.macro';

class App extends Component {
  const a = 0;
  render() {
    return tersus(
      <>
        <div tj-for={['a','b','c','d','e']}>
          <b>{'--value'}</b>
          <i>{'--index'}</i>
        </div>
      </>
    )
  }
}

is equivalent to

class App extends Component {
  const a = 0;
  render() {
    return (
      <>
        {['a', 'b', 'c', 'd', 'e'].map((value, index) => <><div>
          <b>{value}</b>
          <i>{index}</i>
        </div></>)}
      </>
    )
  }
}

Advance mix use-case

import tersus from 'tersus-jsx.macro';

class App extends Component {
  const a = 0;
  render() {
    return tersus(
      <>
        <div tj-if={a === 0}>
          <div tj-for={['a','b','c','d','e']}>
            <div tj-if={'--value'=== c}>
              {'--value'}
            </div>
          </div>
        </div> 
      </>
    )
  }
}

is equivalent to

class App extends Component {
  const a = 0;
  render() {
    return (
      <>
        {a === 0 && <><div>
          {['a', 'b', 'c', 'd', 'e'].map((value, index) => <><div>
            {value === c && <><div>
              {value}
            </div></>}
          </div></>)}
        </div></>} 
      </>
    )
  }
}

License

MIT