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

gulp-style-vars

v1.0.1

Published

A single source for frontend variables, compiling to SASS and JS.

Downloads

2

Readme

gulp-style-vars

A simple module to allow style configuration to be shared across the codebase.

Each input file is given as an anonymous Javascript function which returns a JSON object, which can be parsed into readable representations for each system.

All basic JSON structures are supported, including objects and lists.

The following is a basic example of the input file used by the system.

function() {
  return {
    "sidebar-width": "50px",
    "color-scheme": {
      "theme": "#666666",
      "background": "#333333"
    },
    "width-breakpoints": [
      "800px",
      "1200px"
    ]
  };
}

Currently, this representation can be automatically converted to both SCSS and a standalone JS module.

StyleVars.toSass(src_globs, dest_folder, options)

Takes any file matching src_globs, interprets it as the StyleVars representation and converts to a SCSS variable file and outputs it to the specified folder.

Configurable options are

  • options.prefix String - A prefix to add to the compiled SCSS files, defaults to "_".
  • options.extension String - The extension to set for the output files, defaults to ".scss".
  • options.indent Integer - The number of spaces to indent by, defaults to 4.
  • options.label String - A label to be used for logging, defaults to a string representation of the source globs.
  • options.cb Function - A function to call on completion, will not be called if none is provided.

Running the example above, we get

$sidebar-width: 50px;
$color-scheme: (
    "theme": #666666,
    "background": #333333
);
$width-breakpoints: (
    800px,
    1200px
);

StyleVars.toModule(src_globs, dest_folder, options)

Takes any file matching src_globs, interprets it as the StyleVars representation and converts to a standalone Javascript module (which can be required) and outputs it to the specified folder.

Configurable options are

  • options.prefix String - A prefix to add to the compiled JS files, defaults to "".
  • options.extension String - The extension to set for the output files, defaults to ".js".
  • options.definition String - A definition prefix to add to the contents of the compiled file, defaults to "module.exports = ".
  • options.indent Integer - The number of spaces to indent by, defaults to 4.
  • options.label String - A label to be used for logging, defaults to a string representation of the source globs.
  • options.cb Function - A function to call on completion, will not be called if none is provided.

Running the example above, we get

module.exports = {
    "sidebar-width": "50px",
    "color-scheme": {
        "theme": "#666666",
        "background": "#333333"
    },
    "width-breakpoints": [
        "800px",
        "1200px"
    ]
};

More complicated input files

Though everything can be done statically in the input file, all code will be evaluated on load, so more complicated structures are possible. Anything that returns a JSON object is valid, and will be compiled.

input: config.js

function() {
  var colors = {
    "red": "#ff0000",
    "green": "#00ff00"
  };

  var config = {
    "theme-color": colors["red"],
    "sidebar-width": "200px",
    "app-width": "1000px"
  };

  config["content-width"] = (parseInt(config["app-width"]) - parseInt(config["sidebar-width"])) + "px";

  return config;
}

output: config.js

module.exports = {
    "theme-color": "#ff0000",
    "sidebar-width": "200px",
    "app-width": "1000px",
    "content-width": "800px"
};

output: _config.scss

$theme-color: #ff0000;
$sidebar-width: 200px;
$app-width: 1000px;
$content-width: 800px;