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

encapsulate

v1.1.0

Published

CSS encapsulation for React components

Downloads

11

Readme

encapsulate

Transform CSS and JSX content by scoping the CSS classes to a provided module name.

why

To prevent CSS styles intended for specific React components to cascade and apply to other components, encapsulate ensures that all elements are given a class name and all CSS styles are scoped to the same class. For example, given a class name of FooComponent-1-0-0 the JSX and CSS

<section>
    <h1 className={this.props.headerClass}>Hello World</h1>
    <p className="small">This is some text.</p>
</section>
section: {
    background-color: grey;
}

section h1 {
    display: inline-block;
}

section p.small {
    font-size: 10px;
}

are transformed into

<section className="FooComponent-1-0-0">
    <h1 className={this.props.headerClass + ' FooComponent-1-0-0'}>Hello World</h1>
    <p className="small FooComponent-1-0-0">This is some text.</p>
</section>
section.FooComponent-1-0-0: {
    background-color: grey;
}

section.FooComponent-1-0-0 h1.FooComponent-1-0-0 {
    display: inline-block;
}

section.FooComponent-1-0-0 p.small.FooComponent-1-0-0 {
    font-size: 10px;
}

how

There are a couple ways to use encapsulate

specifying a custom CSS class name

let encapsulate = require('encapsulate');

// somehow populate the JSX and CSS into these
let jsxContent;
let cssContent;

let transformedJsx = encapsulate.transformJsx(jsxContent, 'FooComponent-1-0-0');
let transformedCss = encapsulate.transformCss(cssContent, 'FooComponent-1-0-0');

computing the CSS class name from a package.json file

let encapsulate = require('encapsulate');

// somehow populate the JSX and CSS into these
let jsxContent;
let cssContent;

// This can be any path that that has a package.json in its hierarchy
// e.g. /path/to/the/module
// /path/to/the/module/package.json
// /path/to/the/module/some/other/file
let pathToModule = '/path/to/module';

let transformedJsx = encapsulate.encapsulateJsxWithPackage(pathToModule, jsxContent);
let transformedCss = encapsulate.encapsulateCssWithPackage(pathToModule, cssContent);

developing

git clone the repository and npm install to install all of the dependencies needed to build & run tests.

running tests

npm test

building

gulp build transpiles the encapsulate code into the dist directory.