Giter Site home page Giter Site logo

css.of's Introduction

css.of

A lightweight, dependency free node.js package for creating css strings out of javascript objects.

Features

  • Supports deep nesting;
  • Supports all css statements (yes, including at rules!);
  • Custom indentation;
  • Returns clean, vanilla css.

Installation

Run npm i css.of in the command line.

Usage

const css = require('css.of');

const obj  = {
  '@charset': '"utf-8"',
  '@import': 'url(custom.css)',
  'body': {
    'font': '14px/1.2 sans-serif',
    'color': 'pink',
    'background': '#e3e3e3'
  },
  '#menu nav': {
    'display': 'flex',
    'width': '100%',
    'margin': '30px',
    'border': '1px solid #000'
  },
  '.title': {
    'font-size': '1.5em'
  },
  '@media (min-width: 480px)': {
    'header': {
      'position': 'absolute',
      'top': '0',
      'background': 'rgba(0, 0, 0, .3)'
    },
    'footer': {
      'font-style': 'italic',
      'background': 'black'
    }
  }
};

console.log(css.of(obj));

the above code will return...

@charset "utf-8";
@import url(custom.css);
body {
  font: 14px/1.2 sans-serif;
  color: pink;
  background: #e3e3e3;
}
#menu nav {
  display: flex;
  width: 100%;
  margin: 30px;
  border: 1px solid #000;
}
.title {
  font-size: 1.5em;
}
@media (min-width: 480px) {
  header {
    position: absolute;
    top: 0;
    background: rgba(0, 0, 0, .3);
  }
  footer {
    font-style: italic;
    background: black;
  }
}

Function

css.of(obj = {}, tab = '\t');

Parameters

obj

<object> to create a css string out of

tab

<string> for custom indentation; the default value is \t

Return Value

css

<string> with valid css syntax

License

MIT © 2018 Paula Griguță [email protected]

css.of's People

Contributors

paulabianca avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.