0.1.3 • Published 5 years ago

convert-css v0.1.3

Weekly downloads
6
License
MIT
Repository
-
Last release
5 years ago

Build Status

convert-css

Parse and convert css. The focus is on JSON as it's needed for other services, and other easier conversions like modules in js for css-in-js.

Install

$ npm install convert-css --save

Usage

const fs = require('fs');
const { cssToCamelizedJson } = require('convert-css');

const handleErr = (err) => {
  if(err) {
    console.error(err);
  }
};

fs.readFile('./my.css', 'utf-8', (err, data) => {
  handleErr(err);

  const cssText = data.toString();
  const cssInJs = 'module.exports = ' + JSON.stringify(
    cssToCamelizedJson(data), null, 2
  );

  fs.writeFile('./myCss.js', Buffer.from(cssInJs), (error) => {
    handleErr(error)
    console.log('done!')
  });
});

Documentation

Table of Contents

sequence

sequence takes in functions and calls them in sequence, same as pipe

Parameters

Returns Any result of last function in sequence

replaceCssSyntax

replaceCssSyntax is a function will pipe a string key through more functions to replace and normalize css rule keys

Type: String

convertKey

convertKey replaces css selector syntax with underscores

Parameters

Returns [String] reformatted selector key

mungeRules

mungeRules reformats rules array from css ast

Parameters

Returns [Array] array of css rules with keys for JSON

cssToJson

cssToJson takes a string as a parameter and returns JSON

Parameters

Returns [Object] JSON derived from css ast

cssToCamelizedJson

cssToCamelizedJson takes a string as a parameter and returns JSON

Parameters

Returns [Object] camelized values in JSON object derviced from ast

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

7 years ago

0.1.0

7 years ago