Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
babel-plugin-display-name-custom
Advanced tools
Readme
display name inference for your custom react component creators
so that instead of
you could see
in React Developer Tools for code like
import {createComponent} from "./create";
const Container = createComponent("div", {
border: "1px solid black",
});
const Red = createComponent("div", {
color: "red",
});
const Green = createComponent("div", {
color: "green",
});
const Blue = createComponent("div", {
color: "blue",
});
const Root = () => (
<Container>
<Red>red</Red>
<Green>green</Green>
<Blue>blue</Blue>
</Container>
);
install
yarn add babel-plugin-display-name-custom
add display-name-custom
to .babelrc
{
"presets": ["es2015", "react"],
"plugins": [
"syntax-object-rest-spread",
"transform-object-rest-spread",
["display-name-custom", {
"modules": {
"./create": {
"createComponent": true
}
}
}]
]
}
The modules
object is a mapping of module names to the exported
functions which return new React components.
In the above example ./create
is
export const createComponent = (Component, styles) => {
return props => <Component {...props} style={styles} />;
};
You can also add inference to 3rd party modules
{
"modules": {
"react-redux": {
"connect": true
}
}
}
The default export can be added using the default
keyword
{
"modules": {
"create-component": {
"default": true
}
}
}
After the plugin is configured it knows which functions return new React components.
Using that information it scans your source code for variable declarations which are initialized
using those. When a declaration is found it sets the displayName
property
of the component to the variable name.
In practice it transpiles
const Red = createComponent("div", {
color: "red",
});
to
const Red = createComponent("div", {
color: "red",
});
Red.displayName = "Red";
For library authors the plugin also exports a createPlugin
factory
for generating preconfigured library specific display name plugins.
Just add babel.js
to the root of your npm module with contents like
module.exports = require("babel-plugin-display-name-custom").createPlugin({
modules: {
"mylib": {createComponent: true},
},
});
and your users then can use it with just
{
"presets": ["es2015", "react"],
"plugins": [
"mylib/babel"
]
}
Checkout react-simple for a real world example
FAQs
Display name inference for your custom React component creators.
The npm package babel-plugin-display-name-custom receives a total of 11 weekly downloads. As such, babel-plugin-display-name-custom popularity was classified as not popular.
We found that babel-plugin-display-name-custom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.