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

mini-sass

v1.0.1

Published

Light-weight scss compiler written in Javascript

Downloads

7

Readme

mini-sass

An attempt at building a scss-like compiler in Javascript. SCSS/SASS is a superset of CSS that provides additional functionality like variables and functions.

Install

For CLI:

npm install mini-sass -g

For programmatic use:

npm install mini-sass

Usage

CLI:

mini-sass [options] <files...>

If no input files are specified, mini-sass will read from STDIN. If no flags are specified, mini-sass will print to STDOUT.

Options

Options:
  -o, --output <file>  Output file (default: STDOUT)
  -s, --separate       Generate separate output file for each input

When the -o flag is present, result of compiling all input files will be concatenated into a single file.

When the -s flag is present, each file compiled will be put into its own file terminated with the .css extension

Examples

mini-sass myfile.scss -o output.css

Will generate a single file output.css

mini-sass myfile1.scss myfile2.scss -s

Will generate two files: myfile1.css and myfile2.css corresponding to each input.

API References

Assuming proper installation, load as follows:

var miniSass = require("mini-sass");

There is a single high-level function compile that takes a SCSS string and returns the compiled CSS string:

var scss = "$var: 2px; div { width: $var; }"
var css = miniSass.compile(scss);
console.log(css) // "div { \n width: 2px; \n }"

Features

  • Variables
$var: 20px;

div{
    width: $var;
}
  • Nested Styles
div {
    ul{
        background: green;
    }
}
  • Mixins
@mixin reset-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

div{
    @include reset-list;
}

IMPORTANT

This compiler is not entirely rigorous and will most likely fail in certain cases.

How it works

First, a lexical analysis is performed, converting source code into a stream of tokens, such as IDs, brackets, etc. This corresponds to src/lexer.js

Then a parser converts the stream of tokens into an abstract syntax tree (AST), a data structure that represents the input as a tree based on a Context-Free Grammer. More accurately, the parser gets the next token in the stream by calling the token() method. The parser and corresponding grammar exist in src/parser.js

Finally, the generator takes the AST and produces an output string based on various rules (i.e. the features listed above). This corresponds to src/generator.js

TO DO

  • Interpolation
  • Partials and extended @import
  • Extend API to allow retrieval of AST and tokens

Contributions welcome

Tests

This project uses mocha and chai with babel for test located in test/index.js. Run tests using the following command

npm run test