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

rtl-css-js

v1.16.1

Published

Right To Left conversion for CSS in JS objects

Downloads

7,063,712

Readme

rtl-css-js

RTL conversion for CSS in JS objects

Build Status Code Coverage version downloads MIT License ![All Contributors][all-contributors-badge] PRs Welcome Code of Conduct

The problem

For some locales, it's necessary to change padding-left to padding-right when your text direction is right to left. There are tools like this for CSS (cssjanus for example) which manipulate strings of CSS to do this, but none for CSS in JS where your CSS is represented by an object.

This solution

This is a function which accepts a CSS in JS object and can convert padding-left to padding-right as well as all other properties where it makes sense to do that (at least, that's what it's going to be when it's done... This is a work in progress).

Table of Contentss

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save rtl-css-js

Usage

This module is exposed via CommonJS as well as UMD with the global as rtlCSSJS

CommonJS:

const rtlCSSJS = require('rtl-css-js')
const styles = rtlCSSJS({paddingLeft: 23})
console.log(styles) // logs {paddingRight: 23}

You can also just include a script tag in your browser and use the rtlCSSJS variable:

<script src="https://unpkg.com/rtl-css-js"></script>
<script>
  const styles = rtlCSSJS({paddingRight: 23})
  console.log(styles) // logs {paddingLeft: 23}
</script>

You can also control which rules you don't want to flip by adding a /* @noflip */ CSS comment to your rule

const rtlCSSJS = require('rtl-css-js')
const styles = rtlCSSJS({paddingLeft: '20px /* @noflip */'})
console.log(styles) // logs {paddingLeft: '20px /* @noflip */' }

kebab-case

This library support kebab-case properties too.

const rtlCSSJS = require('rtl-css-js')
const styles = rtlCSSJS({'padding-right': 23})
console.log(styles) // logs {'padding-left': 23}

core

rtl-css-js also exposes its internal helpers and utilities so you can deal with certain scenarios yourself. To use these you can use the rtlCSSJSCore global with the UMD build, require('rtl-css-js/core'), or use import {propertyValueConverters, arrayToObject} from 'rtl-css-js/core'.

You can import anything that's exported from src/core. Please see the code comments for documentation on how to use these.

Caveats

background

Right now background and backgroundImage just replace all instances of ltr with rtl and right with left. This is so you can have a different image for your LTR and RTL, and in order to flip linear gradients. Note that this is case sensitive! Must be lower case. Note also that it will not change bright to bleft. It's a little smarter than that. But this is definitely something to consider with your URLs.

CSS variables - var()

Since it's impossible to know what the contents of a css variable are until the styles are actually calculated by the browser, any CSS variable contents will not be converted.

Inspiration

CSSJanus was a major inspiration.

Ecosystem

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors

Thanks goes to these people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT