npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

css-light

v1.1.0

Published

Write CSS in JavaScript

Readme

css-light

Super light-weight package to write CSS in JavaScript. At only 100 lines of code this module has everything you need to generate CSS from plain JavaScript objects on the server or client.

var css = require('css-light');
console.log(css.css({
    '.block': {
        border: '1px solid red',
    }
}));

This will generate:

.block{border:1px solid red}

Variables

var fontStack = 'Helvetica, sans-serif';
var primaryColor = '#333';
console.log(css.css({
    body: {
        font: `100% ${fontStack}`,
        color: primaryColor,
    }
}));

Output:

body{font:100% Helvetica, sans-serif;color:#333}

Nesting

console.log(css.css({
    nav: {
        ul: {
            mar: 0,
            pad: 0,
            lis: 'none',
        },
        li: {d: 'inline-block'},
        a: {
            d: 'block',
            pad: '6px 12px',
            ted: 'none',
        }
    }
}));

Output:

nav ul{margin:0;padding:0;list-style:none}
nav li{display:inline-block}
nav a{display:block;padding:6px 12px;text-decoration:none}

Mixins

function borderRadius(radius) {
    return {
        '-webkit-border-radius': radius,
        '-moz-border-radius': radius,
        '-ms-border-radius': radius,
        'border-radius': radius,
    };
}
console.log(css.css({
    '.box': borderRadius('10px'),
    '.another-box': [
        borderRadius('20px'),
        {
            'background': 'red',
            '.child': {
                'font-size': '12pt',
            }
        }
    ],
}));

Output:

.box{-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;border-radius:10px}
.another-box{-webkit-border-radius:20px;-moz-border-radius:20px;-ms-border-radius:20px;border-radius:20px;background:red}
.another-box .child{font-size:}

Extend/Inheritance

    var message = {
        bd: '1px solid #ccc',
        pad: '10px',
        col: '#333',
    };
    console.log(css.css({
        '.message': message,
        '.success': css.extend({}, message, {
            'border-color': 'green',
        }),
        '.error': [
            message,
            {
                'border-color': 'red',
            }
        ],
    }));

Output:

.message{border:1px solid #ccc;padding:10px;color:#333}
.success{border:1px solid #ccc;padding:10px;color:#333;border-color:green}
.error{border:1px solid #ccc;padding:10px;color:#333;border-color:red}

Operators

Use standard JavaScript to do calculations *, /, +, -:

console.log(css.css({
    'article[role="main"]': {
        fl: 'left',
        w: 600 / 960 * 100 + '%',
    },
    'aside[role="complementary"]': {
        fl: 'right',
        w: 300 / 960 * 100 + '%',
    }
}));

Output:

article[role="main"]{float:left;width:62.5%}
aside[role="complementary"]{float:right;width:31.25%}

& Operator

The & operator is replaced by the parent selector:

console.log(css.css({
    '.parent': {
        '.child': { color: 'red'},
        '& .child': { color: 'red'},
        '&.child': { color: 'red'},
    }
}));

Output:

.parent .child{color:red}
.parent .child{color:red}
.parent.child{color:red}

Atoms

css-light comes with a short list of atoms for commonly used CSS properties, for example, use pad instead of padding:

console.log(css.css({
    'div': {
        padding: '0 0 0 0',
        pad: '0 0 0 0',
    }
}));

Output:

div{padding:0 0 0 0;padding:0 0 0 0}

Print the full list of atoms:

console.log(css.atoms);

Output:

{
    d:      'display',
    mar:    'margin',
    mart:   'margin-top',
    marr:   'margin-right',
    marb:   'margin-bottom',
    marl:   'margin-left',
    pad:    'padding',
    padt:   'padding-top',
    padr:   'padding-right',
    padb:   'padding-bottom',
    padl:   'padding-left',
    bd:     'border',
    bdt:    'border-top',
    bdr:    'border-right',
    bdb:    'border-bottom',
    bdl:    'border-left',
    bdrad:  'border-radius',
    col:    'color',
    op:     'opacity',
    bg:     'background',
    bgc:    'background-color',
    fz:     'font-size',
    fs:     'font-style',
    fw:     'font-weight',
    ff:     'font-family',
    lh:     'line-height',
    bxz:    'box-sizing',
    w_bxz:  '-webkit-box-sizing',
    m_bxz:  '-moz-box-sizing',
    cur:    'cursor',
    ov:     'overflow',
    pos:    'position',
    ls:     'list-style',
    ta:     'text-align',
    td:     'text-decoration',
    fl:     'float',
    w:      'width',
    h:      'height',
    trs:    'transition',
    out:    'outline',
    vis:    'visibility',
    ww:     'word-wrap',
    con:    'content',
}

Media Queries

// ## Media queries
console.log(css.css({
    '@media (max-width: 600px)': {
        '.facet_sidebar': {
            display: 'none'
        }
    }
}));

Output:

@media (max-width: 600px){
    .facet_sidebar{display:none}
}

Nested lists

console.log(css.css({
    'section, div': {
        'h1, h2': {
            'span, .light': {
                td: 'none'
            },
        },
    },
}));

Output:

section h1 span, div h1 span,section  h2 span, div  h2 span,section h1  .light, div h1  .light,section  h2  .light, div  h2  .light{text-decoration:none}

// ## Overwrite

Add multiple definitions of the same property:

console.log(css.css({
    div: [
        {boder: '1px solid red'},
        {boder: '1px solid green'},
    ]
}));

Output:

div{boder:1px solid red;boder:1px solid green}