Git Product home page Git Product logo

css4ify's Introduction

css4ify

A simple tool to convert CSS to JSON and JSON to CSS.

  • ๐ŸŒฒ Uses csstree to parse CSS
  • ๐Ÿš€ ESM support
  • ๐Ÿค˜ TypeScript support
  • ๐Ÿ”ฎ CSS 4 features supported like CSS Nesting and modern pseudoselectors
  • ๐Ÿ“ฆ Bundled with Bun
  • ๐Ÿ“Ž Lightweight

Usage

npm install css4ify
Convert CSS to JSON
import { jsonify } from 'css4ify';

const json = jsonify(`
  .foo {
    color: red;
  }
  .bar {
    color: blue;

    &:hover {
      color: green;
    }
  }
`);

It will return:

{
  ".foo": {
    "color": "red"
  },
  ".bar": {
    "color": "blue",
    "&:hover": {
      "color": "green"
    }
  }
}
Convert JSON to CSS
import { stringify } from 'css4ify';

const css = stringify({
  ".foo": {
    "color": "red"
  },
  ".bar": {
    "color": "blue",
    "&:hover": {
      "color": "green"
    }
  }
});

It will return:

.foo {
  color: red;
}
.bar {
  color: blue;
  &:hover {
    color: green;
  }
}

Missing features

This project is in early stages and may not support all CSS features. You can help by opening an issue or a pull request.

CSS Nesting is NOT supported when there is properties after the nested selector. For example:

/* This will not work */
.foo {
  color: red;
  &:hover {
    color: green;
  }
  background-color: blue;
}

To solve it, just move the properties to be before the nested selector:

/* This will work */
.foo {
  color: red;
  background-color: blue;
  &:hover {
    color: green;
  }
}

Development

To install dependencies:

bun install

To run:

bun run src/index.ts

This project was created using bun init in bun v1.0.20. Bun is a fast all-in-one JavaScript runtime.

css4ify's People

Contributors

onmax avatar

Watchers

 avatar

css4ify's Issues

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.