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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsheets

v0.3.0

Published

A simple CSS preprocessor that interprets JavaScript

Downloads

28

Readme

jsheets(1)

v0.3.0 - A simple CSS preprocessor that interprets JavaScript

SYNOPSYS

jsheets file

DESCRIPTION

Jsheets is a CSS preprocessor that executes JavaScript. It also replaces function calls and variables inside CSS. A simple approach to CSS preprocessing.

INSTALL

npm install -g jsheets

SYNTAX

The $ Object

Inside CSS the whole $ object is availible to you. Because $ is also a function (as explained in the helpers section), you can't write to its arguments, caller, length and prototype attributes.

div {
  background: $.someColor;
}

include

include 'file/directory'

With include you can import files or directories to a jsheet. When you include a directory, it will search that directory for files with the jsheet file extension.

css()

css(string)

With the css function you can output css. So you can do:

css('div {display: block}')

Variable Scope

All combined files have the same global scope.

Globals

Inside your JavaScript you have the following variables availible to you.

_

The underscore library

require

The nodejs require function

css

As documented above

hooks

Documented in the hooks section

on

on(hook, function)

on is the function to add functions to hooks. See under the hooks section for examples.

helpers

There are some helpers provided inside the $ object.

$

$(expression)

$ itself is not just an object but also a function that executes and returns what is passed to it. This can be usefull for math or sometimes you can use it to use variables in weird places. Example:

div {
  width: $(100 * 30)px
  /* WON'T WORK */
  width: $.someWithem
  /* WILL WORK */
  width: $($.someWith)em
}

You cannot use braces inside of a call to $. That's because the $ variables and functions are replaced using a mediocar RegEx.

extend

extend.add(name, attributes)

extend.that(name, selector)

With extend you can reuse css attributes. It has two methods: add and that. With add you create save a bunch of attributes under a name.

$.extend.add('roundbutton', '\
  display: block;'
)

Then with extend.that you can then reuse those attributes.

$.extend.that('roundbutton', '.dialogue__button')
$.extend.that('roundbutton', '.escape__button')

What is special about this function, is that it renders only one CSS block per extend.add. So the above renders to:

roundbutton, .dialogue__button, .escape__button {  display: block; }

calc

$.calc(calculation)

With calc you can do calculations in css units. You pass it a string. It also does a printf-style replacement with %d.

$.someVar = '4rem'
$.calc('%d / 2', $.someVar)

compilesTo

2rem

Hooks

In jsheets hooks are simple arrays you can push functions to. They are stored in the hooks object, which is globally availible. Hooks get triggered at a certain point in the parsing process and then the functions stored in a hook array will get executed with certain parameters.

onEOF

These hooks are executed without an argument, at the and of parsing a file. The return value of a onEOF hook will get printed as CSS.

Extensions

Extending jsheets is super straigt forward. If you want to add your own helpers, you can just add stuff to the object.

$.myHelper = function () {
  css('before: "YEY! I wrote my own helper :OO"')
}

You can also install and require npm modules. Autoprefixer for example

npm install autoprefixer
on('onEOF', require('autoprefixer'))

onAfterParse

onAfterParse hooks are the last thing that gets called. They receive the parsed CSS as an argument. Their return value replaces the parsed CSS. This makes it perfect for something like autoprefixer.

ROADMAP

I'm pretty ok with the package as it stands right now. But there are a lot of things I plan to implement.

  • Integration
    • express
    • meteor
  • Highlighting
    • SublimeText

TODO

  • Fix the onAfterParse hook to only execute once

Changelog - v0.3.0

This is still an early alpha, so everything can change

  • Added this file (changelog)
  • Rewrote the hooks interface
  • All files have the same global scope now
  • Fixed my version numbers (again) #fubar