Socket
Socket
Sign inDemoInstall

icss-utils

Package Overview
Dependencies
9
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    icss-utils

ICSS utils for postcss ast


Version published
Maintainers
2
Install size
1.50 MB
Created

Package description

What is icss-utils?

The icss-utils package provides utilities for working with ICSS (Interoperable CSS), which is a convention for handling CSS modules. It allows for the extraction and manipulation of CSS module content, such as importing/exporting variables and handling scoped CSS.

What are icss-utils's main functionalities?

Extracting ICSS imports and exports

This feature allows you to extract ICSS imports and exports from a CSS string. The `extractICSS` function returns an object with `icssImports` and `icssExports` properties, which contain the extracted values.

const { extractICSS } = require('icss-utils');
const css = ':export { color: red; }';
const { icssImports, icssExports } = extractICSS(css);

Replacing values in CSS

This feature enables you to replace symbols in a CSS string with specified values. The `replaceSymbols` function takes a CSS string and an object of replacements, then returns the CSS with the values replaced.

const { replaceSymbols } = require('icss-utils');
const css = '.className { color: colorValue; }';
const replacements = { colorValue: 'red' };
const result = replaceSymbols(css, replacements);

Creating an ICSS replacement map

This feature helps in creating a map of ICSS replacements from exports. The `createICSSReplacements` function takes an object of ICSS exports and returns an object that can be used for replacing symbols in CSS.

const { createICSSReplacements } = require('icss-utils');
const icssExports = { color: 'red' };
const replacements = createICSSReplacements(icssExports);

Other packages similar to icss-utils

Readme

Source

Build Status

ICSS Utils

replaceSymbols

Governs the way tokens are searched & replaced during the linking stage of ICSS loading.

This is broken into its own module in case the behaviour needs to be replicated in other PostCSS plugins (i.e. CSS Modules Values)

import { replaceSymbols, replaceValueSymbols } from "icss-utils"
replaceSymbols(css, replacements)
replaceValueSymbols(string, replacements)

Where:

  • css is the PostCSS tree you're working with
  • replacements is an JS object of symbol: "replacement" pairs, where all occurrences of symbol are replaced with replacement.

A symbol is a string of alphanumeric, - or _ characters. A replacement can be any string. They are replaced in the following places:

  • In the value of a declaration, i.e. color: my_symbol; or box-shadow: 0 0 blur spread shadow-color
  • In a media expression i.e. @media small {} or @media screen and not-large {}

extractICSS(css, removeRules = true)

Extracts and remove (if removeRules is equal true) from PostCSS tree :import and :export statements.

import postcss from 'postcss';
import { extractICSS } from 'icss-utils'

const css = postcss.parse(`
  :import(colors) {
    a: b;
  }
  :export {
    c: d;
  }
`)

extractICSS(css)
/*
  {
    icssImports: {
      colors: {
        a: 'b'
      }
    },
    icssExports: {
      c: 'd'
    }
  }
*/

createICSSRules(icssImports, icssExports)

Converts icss imports and exports definitions to postcss ast

createICSSRules({
  colors: {
    a: 'b'
  }
}, {
  c: 'd'
})

License

ISC


Glen Maddern and Bogdan Chadkin, 2015.

Keywords

FAQs

Last updated on 26 May 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc