Socket
Book a DemoInstallSign in
Socket

css4ify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css4ify

Convert CSS to JSON

0.0.2
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

css4ify

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

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.

FAQs

Package last updated on 05 Mar 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.