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

sass-color-json

v0.4.0

Published

Generate json based on SASS color variables.

Downloads

98

Readme

#SASS-COLOR-JSON Convert any SASS file with color variables to a json file.

Travis CI Version NPM Downloads LICENSE

We currently support: hex colors (3 or 6 character), rgb, hsl, rgba & hsla.

Module can be used as CLI or within your node project.

As of version 0.2.0 We now have a Synchronous (0.1.0) and Asynchronous version. The CLI still relies on the synchronous version. No other options have changed. The script overall was made shorter and faster.

###Options (as json object {}) input

Required: True

Type: String

Default: " "

output

Required: False

Type: String

Default: False

When not supplied: Returns JSON object

isString Require: False

Type: Boolean

Default: False

###Example SASS / SCSS

//Example SASS -> JSON
$red-short: #d00;
$red-long:  #dd0000;
$red-rgb:   rgb(221, 0, 0);
$red-rgba:  rgba(221, 0, 0, .5);
$red-hsl:   hsl(0, 100, 47);
$red-hsla:  hsla(0, 100, 47, .5);

Terminal:

$ sass-color-json --input ~/_colors.scss --output ~/colors.json

Node Module

/**
 * BLOCKING SYNC VERSION
**/
var sassColorJson = require('sass-color-json'),
  sassColorOptions = {
    input: '_colors.scss'
  },
  jsonObj = sassColorJson.sync(sassColorOptions);

console.log(jsonObj);

/**
 * NON-BLOCKING ASYNC VERSION
 * Async keeps all the same functionality as previous versions, but is non-blocking.
**/
sassColorJson.async(sassColorOptions, function (err, data) {
  if (err) {
    throw new Error('Error: ' + err);
  }

  console.log(data);
});

/**
 * Processing Strings
**/
var buffer = fs.readFile('_colors.scss', function (err, data) {
    if (err) {
        throw new Error('Error: ' + err);
    }

    var sassColorOptions = {
        input: data,
        isString: true
    };

    sassColorJson.async(sassColorOptions, function (err, data) {
      if (err) {
        throw new Error('Error: ' + err);
      }

      console.log(data);
    });
});

Output:

{
  "red-short": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-short: #d00;",
    "original": {
      "name": "$red-short:",
      "value": "d00;",
      "full": "$red-short: #d00;"
    },
    "name": "red-short",
    "type": "#",
    "value": "d00"
  },
  "red-long": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-long: #dd0000;",
    "original": {
      "name": "$red-long:",
      "value": "dd0000;",
      "full": "$red-long:  #dd0000;"
    },
    "name": "red-long",
    "type": "#",
    "value": "dd0000"
  },
  "red-rgb": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-rgb: rgb(221, 0, 0);",
    "original": {
      "name": "$red-rgb:",
      "value": "(221, 0, 0);",
      "full": "$red-rgb:   rgb(221, 0, 0);"
    },
    "name": "red-rgb",
    "type": "rgb",
    "value": "(221, 0, 0)"
  },
  "red-rgba": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-rgba: rgba(221, 0, 0, .5);",
    "original": {
      "name": "$red-rgba:",
      "value": "(221, 0, 0, .5);",
      "full": "$red-rgba:  rgba(221, 0, 0, .5);"
    },
    "name": "red-rgba",
    "type": "rgba",
    "value": "(221, 0, 0, .5)"
  },
  "red-hsl": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-hsl: hsl(0, 100, 47);",
    "original": {
      "name": "$red-hsl:",
      "value": "(0, 100, 47);",
      "full": "$red-hsl:   hsl(0, 100, 47);"
    },
    "name": "red-hsl",
    "type": "hsl",
    "value": "(0, 100, 47)"
  },
  "red-hsla": {
    "aliases": false,
    "isAlias": false,
    "full": "$red-hsla: hsla(0, 100, 47, .5);",
    "original": {
      "name": "$red-hsla:",
      "value": "(0, 100, 47, .5);",
      "full": "$red-hsla:  hsla(0, 100, 47, .5);"
    },
    "name": "red-hsla",
    "type": "hsla",
    "value": "(0, 100, 47, .5)"
  }
}

###CLI Shortcuts input: -i, --file, -f

output: -o

###Notes If no output is suppled the module returns JSON Object.

If output is only a directory module assumes filename sass-variables.json