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-sass

v2.0.0

Published

Right-to-left done right with Sass

Downloads

973

Readme

Right-to-Left NPM version

Right-to-left done right with Sass

Right-to-left makes supporting right-to-left languages in Sass super simple. Use the provided mixins instead of their belonging CSS declarations and you're done!

Provided mixins

Alignment

  • text-align($value)

Border

  • border-bottom-left-radius($value)
  • border-bottom-right-radius($value)
  • border-color($top, $right: null, $bottom: null, $left: null)
  • border-left($value)
  • border-left-color($value)
  • border-left-style($value)
  • border-left-width($value)
  • border-radius($topLeft, $topRight: null, $bottomRight: null, $bottomLeft: null)
  • border-right($value)
  • border-right-color($value)
  • border-right-style($value)
  • border-right-width($value)
  • border-style($top, $right: null, $bottom: null, $left: null)
  • border-top-left-radius($value)
  • border-top-right-radius($value)
  • border-width($top, $right: null, $bottom: null, $left: null)

Margin

  • margin($top, $right: null, $bottom: null, $left: null)
  • margin-left($value)
  • margin-right($value)

Padding

  • padding($top, $right: null, $bottom: null, $left: null)
  • padding-left($value)
  • padding-right($value)

Positioning

  • float($value)
  • left($value)
  • right($value)

API

Functions

Right-to-left uses the following low-level functions to implement its right-to-left support.

  • extract-1-to-4-values($one, $two: null, $three: null, $four: null)

    Returns a Sass List containing four values conforming to CSS specifications regarding the number of arguments of 1-to-4 declarations: if it is passed four values, they are returned as-it; if $four is missing, it is the same as $two; if $three is missing, it is the same as $one; if $two is missing, it is the same as $one.

Mixins

Right-to-left uses the following low-level mixins to implement its right-to-left support. Feel free to use them to provide right-to-left support to declarations that are not (yet ^^) supported by rtl-sass.

  • declaration($property, $leftToRightValue, $rightToLeftValue)

    The lowest-level API mixin, called by all other mixins of the rtl-sass API. Provides right-to-left support by explicitly passing ltr and rtl values.

    To mimic the hypothetical CSS declaration...

    [dir="ltr"] .dummy {
        dummy-property: left-to-right-value;
    }
      
    [dir="rtl"] .dummy {
        dummy-property: right-to-left-value;
    }

    ...this mixin would be called with the following form:

    @include declaration(dummy-property, left-to-right-value, right-to-left-value);

  • declaration-1-to-4($property, $top, $right: null, $bottom: null, $left: null)

    Used to provide right-to-left support for side-related declarations using 1-to-4 value syntax - for example margin: 20px 10px. This mixin conforms to CSS specifications regarding the number of arguments: if it is passed four values, they set top, right, bottom and left in that order; if $left is missing, it is the same as $right; if $bottom is missing, it is the same as $top; if $right is missing, it is the same as $top.

    $property can be either a Sass String or a Sass List. In the latter case, the first element of the list is considered as the property prefix and the second one (if any) as the property suffix. Any additional element of the list is ignored.

    To add right-to-left support for the hypothetical CSS declaration dummy: 20px 10px 5px 0px, this mixin would be called with one of the following forms:

    @include declaration-1-to-4(dummy, 20px, 10px, 5px, 0px);

    @include declaration-1-to-4((dummy), 20px, 10px, 5px, 0px);

    ...and would compile into:

    .test {
        dummy-top: 20px;
        dummy-bottom: 5px;
    }
      
    [dir=ltr] .test {
        dummy-right: 10px;
        dummy-left: 0;
    }
      
    [dir=rtl] .test {
        dummy-right: 0;
        dummy-left: 10px;
    }   

    To add right-to-left support for the hypothetical CSS declaration dummy-width: 20px 10px 5px 0px, this mixin would be called with the following form...

    @include declaration-1-to-4((dummy, width), 20px, 10px, 5px, 0px);

    ...and would compile into:

    .test {
        dummy-top-width: 20px;
        dummy-bottom-width: 5px;
    }
      
    [dir=ltr] .test {
        dummy-right-width: 10px;
        dummy-left-width: 0;
    }
      
    [dir=rtl] .test {
        dummy-right-width: 0;
        dummy-left-width: 10px;
    }
  • declaration-1-to-4-corner($property, $topLeft, $topRight: null, $bottomRight: null, $bottomLeft: null)

    Used to provide right-to-left support for corner-related declarations using 1-to-4 value syntax - for example radius: 20px 10px. This mixin conforms to CSS specifications regarding the number of arguments: if it is passed four values, they set top-left, top-right, bottom-right and bottom-left in that order; if $bottomLeft is omitted it is the same as $topRight; if $bottomRight is omitted it is the same as $topLeft; if $topRight is omitted it is the same as $topLeft.

    $property can be either a Sass String or a Sass List. In the latter case, the first element of the list is considered as the property prefix and the second one (if any) as the property suffix. Any additional element of the list is ignored.

    To add right-to-left support for the hypothetical CSS declaration dummy: 20px 10px 5px 0px, this mixin would be called with one of the following forms:

    @include declaration-1-to-4-corner(dummy, 20px, 10px, 5px, 0px);

    @include declaration-1-to-4-corner((dummy), 20px, 10px, 5px, 0px);

    ...and would compile into:

    [dir=ltr] .test {
        dummy-top-left: 20px;
        dummy-top-right: 10px;
        dummy-bottom-right: 5px;
        dummy-bottom-left: 0;
    }
         
    [dir=rtl] .test {
        dummy-top-left: 10px;
        dummy-top-right: 20px;
        dummy-bottom-right: 0;
        dummy-bottom-left: 5px;
    }

    To add right-to-left support for the hypothetical CSS declaration dummy-radius: 20px 10px 5px 0px, this mixin would be called with the following form...

    @include declaration-1-to-4-corner((dummy, radius), 20px, 10px, 5px, 0px);

    ...and would compile into:

    [dir=ltr] .test {
        dummy-top-left-radius: 20px;
        dummy-top-right-radius: 10px;
        dummy-bottom-right-radius: 5px;
        dummy-bottom-left-radius: 0;
    }
      
    [dir=rtl] .test {
        dummy-top-left-radius: 10px;
        dummy-top-right-radius: 20px;
        dummy-bottom-right-radius: 0;
        dummy-bottom-left-radius: 5px;
    }
  • declaration-value($property, $value)

    Used to provide right-to-left support for declarations where the position is the value of the property - for example text-align: left.

    To add right-to-left support for the hypothetical CSS declaration dummy: left, this mixin would be called with the following form:

    @include declaration-value(dummy, left);

How to use

First, install rtl-sass:

npm i rtl-sass

Then use the module:

@use "{relative/path/to/node_modules}/rtl-sass" as Rtl;

.foo {
  Rtl.border-color(orangered);
}

You can also use each module independently:

@use "{relative/path/to/node_modules}/rtl-sass/api" as Api;
@use "{relative/path/to/node_modules}/rtl-sass/border" as Border;

.foo {
  @include Api.declaration(float, left, right);
  @include Border.border-color(black);
}

Contributing

  • Fork the main repository
  • Code
  • Implement tests using node-tap
  • Issue a pull request keeping in mind that all pull requests must reference an issue in the issue queue

License

Apache-2.0 © Eric MORAND