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

babel-plugin-transform-html-to-primitives

v0.0.5

Published

Transforms HTML tags in JSX to their Primitive equivalents

Downloads

11

Readme

babel-plugin-transform-html-to-primitives

Transforms HTML tags in JSX to their Primitive equivalents

Example

In

import React from 'react';
import { Image, View, Text } from 'react-primitives';
import styled from 'styled-components/primitives';


const ButtonElement = styled.button`
    height: 50px;
    padding: 0 10px;
    border-radius: 3px;
    background-color: #595959;
`;

const textStyle = {
    lineHeight: 50,
    color: '#FFFFFF',
    textAlign: 'center'
};


const Button = ({ relative }) => (
  <ButtonElement>
  	<img src="/photo.jpg" alt={relative} />
  	<span style={textStyle}>Luke, I am your <strong className="relative">{relative}</strong>.</span>
  </ButtonElement>
);

Button.defaultProps = {
    relative: 'father'
};

export default Button;

Out

import React from 'react';
import { Image, View, Text } from 'react-primitives';
import styled from 'styled-components/primitives';


const ButtonElement = styled(View)`
    height: 50px;
    padding: 0 10px;
    border-radius: 3px;
    background-color: #595959;
`;

const textStyle = {
    lineHeight: 50,
    color: '#FFFFFF',
    textAlign: 'center'
};


const Button = ({ relative }) => (
  <ButtonElement>
  	<Image source="/photo.jpg" alt={relative} />
  	<Text style={textStyle}>Luke, I am your <Text className="relative">{relative}</Text>.</Text>
  </ButtonElement>
);

Button.defaultProps = {
    relative: 'father'
};

export default Button;

Installation

$ npm install babel-plugin-transform-html-to-primitives

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-html-to-primitives"]
}

With options:

{
  "plugins": [
    ["transform-html-to-primitives", {
      "primitives": {
        "blockquote": "View",
        "pre": "View"
      },
      "primitiveProp": "primitive",
      "tagNameProp": "tagName"
    }]
  ]
}

Via CLI

$ babel --plugins transform-html-to-primitives script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-html-to-primitives"]
});

Options

primitives

object

Overrides the default tag-to-primitive mapping.

In

<blockquote>something</blockquote>

Out (with default options)

{
  "plugins": ["transform-html-to-primitives"]
}
<Text>something</Text>

Out (with "primitives" override)

{
  "plugins": [
    ["transform-html-to-primitives", {
      "primitives": {
          "blockquote": "View"
      }
    }]
  ]
}
<View>something</View>

primitiveProp

string

The prop name that will tell the transpiler which primitive to use in this specific case. Useful for html tags that may act as different primitives in different places, like the <a> tag.

In (with default options)

<a href="/link-to-page-a">Page A</a>

Out (with default options)

{
  "plugins": ["transform-html-to-primitives"]
}
<Text href="/link-to-page-a">Page A</Text>

In (with "primitiveProp")

<a href="/link-to-page-a" myCrazyPrimitive="View">Page B</a>

Out (with "primitiveProp")

{
  "plugins": [
    ["transform-html-to-primitives", {
      "primitiveProp": "myCrazyPrimitive"
    }]
  ]
}
<View href="/link-to-page-a">Page B</View>

tagNameProp

string

The prop name that will pass the original tag name to the primitives. In case you are implementing your own primitives.

In

<span>something</span>

Out (with "tagNameProp")

{
  "plugins": [
    ["transform-html-to-primitives", {
      "tagNameProp": "theTagILoved"
    }]
  ]
}
<Text theTagILoved="span">something</Text>