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 🙏

© 2022 – Pkg Stats / Ryan Hefner

stylex

v0.3.0

Published

Easily convert CSS styles between the DOM and Javascript, and back.

Downloads

33

Readme

Stylex

npm NPM npm Snyk Vulnerabilities for GitHub Repo

Utility for converting CSS styles in the DOM to Javascript, and back.

Install

Via NPM

npm install --save stylex

Via Yarn

yarn add stylex

Methods

Below are the static methods available on the Stylex class, along with examples how each could be used.

Stylex.findDOMStyles(selector)

Method that will return the CSSRule.cssText for the specified CSS selector.

Example

const stylesText = Stylex.findDOMStyles('.example-class-name');

Stylex.convertCssText(CSSRule.cssText)

Converts a CSSRule.cssText string to a JSON object that can be used/manipulated in Javascript.

Example

const styles = Stylex.convertCssText(Stylex.findDOMStyles('.example-class-name'));

Stylex.convertJsonStyles(object)

In the event you need to go the opposite direction, you can convert a JSON object of CSS styles to a string that could be applied as a CSSRule.cssText.

Example

const stylesText = Stylex.convertJsonStyles({
    fontSize: '16px',
    backgroundColor: '#fff',
});

Examples

This class spawned from the need to animate styles via Javascript, but with the goal of being able to keep the styles defined in CSS as much as possible. It allows you to find styles that are available in the DOM and convert those to JSON object(s) that can be manipulated and applied to elements via Javascript.

And, in the event that you need to go the opposite direction—Javascript JSON style object to CSS text—it supports that too! ;)

Obtain Class Styles

Pull the start and end styles for a given element, but calculate the current styles based on a value only available via JS. This could be a progress that is provided via a scroll position, time, or whatever else you might want to use to base the style changes off of. The goal of this being, you don’t have to know the style attributes that are being manipulated, which makes both the javascript and the way you manage styles more flexible.

View Example on Codepen

Name Origin

In case anyone is curious, the name of this package has a dual meaning to me. One, I think it pretty succinctly sums up what this class does, but it has a second reference that is just as cool, to me at least. I went to school at Bowling Green State University, where I was more into bands than school, but I still made it out in 4 years, with good grades. I just didn’t make school my priority while I was there, but back to the bands/music.

While attending school, there was a band that was based out of the BG/Toledo area called, Stylex. They were a new wave band who made some great records, played some equally great shows, and who I occassionally partied with. If you’re looking for some new/old tunes to listen to, I would definitely recommend you check them out! Stylex (the band).

🐺 !!PARTY HOWL!! 🐺

License

MIT © Ryan Hefner