GithubHelp home page GithubHelp logo

alexxnica / icss-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from css-modules/icss-utils

0.0 1.0 0.0 60 KB

Search & replace tokens during the linking stage of ICSS loading

JavaScript 100.00%

icss-utils's Introduction

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.

icss-utils's People

Contributors

geelen avatar trysound avatar markdalgleish avatar greenkeeperio-bot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.