New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fix-a11y-lengths

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fix-a11y-lengths

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.

  • 0.0.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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

➤ 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

FAQs

Package last updated on 05 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc