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

fix-a11y-lengths

v0.0.12

Published

This script transforms CSS length units (e.g., px to rem) based on a configuration, ensuring responsive scaling and accessibility by adapting to changes in base font size.

Downloads

11

Readme

-----------------------------------------------------

➤ CSS Unit Transformer Utility - fix-a11y-lengths

This utility provides functions for transforming CSS unit values (e.g., px, rem) within CSS files or property values based on configurable rules. It includes support for rounding, custom length-matching rules, handling complex CSS properties, and replacing hard-coded lengths with CSS/SCSS variables.

-----------------------------------------------------

➤ Features

  • Unit conversion: Transform values between px and rem or other units.
  • Custom rules: Define your own matching rules for CSS units.
  • Flexible configuration: Supports rounding options and custom size mappings.
  • Replace hard-coded lengths: Replace fixed-length values with CSS/SCSS variables.
  • Complex value transformation: Handle and transform CSS properties with multiple length values.
  • Preserve formatting: Retains the original formatting, including spaces, newlines, and comments, in your CSS.

-----------------------------------------------------

➤ Configuration

The configuration is defined in a .fix-a11y-lengths file. The schema for the configuration is validated using AJV.

Example .fix-a11y-lengths:

{
  "baseFontSize": 16,
  "round": {
    "enabled": true,
    "roundUpOnTie": true
  },
  "lengthMatchingRules": {
    "px": "(-?\d+(\.\d+)?|\.\d+)px",
    "rem": "(-?\d+(\.\d+)?|\.\d+)rem"
  },
  "properties": {
    "width": "rem",
    "padding": "px"
  },
  "sizes": {
    "px": {
      "0": "var(--size-0-in-px)",
      "1": "var(--size-1-in-px)",
      "4": "var(--size-4-in-px)"
    },
    "rem": {
      "0": "var(--size-0-in-rem)",
      "1": "var(--size-1-in-rem)",
      "4": "var(--size-4-in-rem)"
    }
  }
}

In the sizes section, you can define mappings from hard-coded lengths to CSS/SCSS variables. When the utility transforms the file, it will replace any matching length with the corresponding variable.

-----------------------------------------------------

➤ Usage

No installation is required. You can run the utility directly using npx. Simply place your .fix-a11y-lengths file in the same folder where you are executing the command, and the utility will use it as the configuration.

Example Command

npx fix-a11y-lengths@latest [file|folder]

Replace [file|folder] with the path to the CSS file or folder you want to transform.

-----------------------------------------------------

➤ Validation

This utility validates the .fix-a11y-lengths configuration file using AJV (Another JSON Schema Validator). It checks for the structure and correctness of the configuration.

-----------------------------------------------------

➤ Contributing

Feel free to open issues or submit pull requests for enhancements and bug fixes.

-----------------------------------------------------

➤ License

MIT License