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

@vulcancreative/cross-colour

v1.0.0

Published

Dynamically translates a SASS/SCSS colour file to a JS object

Downloads

5

Readme

CrossColour

This is a simple utility, intended for the dynamic (re-)compilation of SASS/SCSS colours to a Javascript file or JSON object. The intent behind this is to keep your code DRY, and ensure cohesive style adherenece throughtout your app. This is currently in production use on our ad agency's website.

The utility can be used in one of two ways. Either as a webpack plugin or as a library.

npm i @vulcancreative/cross-colour --save-dev

Example

CrossColour can take a SCSS colour-reference file:

// vulcan colors
$yellow: #ffe380;
$cyan: #4ec7bc;
$magenta: #fe939d;

// tonals
$white: #ffffff;
$black: #211f22;
$light-grey: #f7f8fa;
$line-grey: #e2e1e5;
$line-darkgrey: #444245;
$mid-grey: #dedede;
$slate-grey: #6e7077;
$dark-grey: #323034;
$space-black: #1e112c;

And it will translate it to something you can use in your JavaScript, without having to worry about code duplication, incorrect colours, or getting slapped around by your design team.

// Auto-generated via CrossColour
const colours = {
  "yellow": "#ffe380",
  "cyan": "#4ec7bc",
  "magenta": "#fe939d",
  "white": "#ffffff",
  "black": "#211f22",
  "lightGrey": "#f7f8fa",
  "lineGrey": "#e2e1e5",
  "lineDarkgrey": "#444245",
  "midGrey": "#dedede",
  "slateGrey": "#6e7077",
  "darkGrey": "#323034",
  "spaceBlack": "#1e112c"
};

export default colours;

CrossColours will ignore comments (including CSS-style block comments) in the final output.

Webpack Use

Webpack use is quite simple. Merely include it in your plugin chain and pass your config. In development mode, rossColour will rebuild your colours for JS whenever it detects your SASS/SCSS file has been updated.

const { CrossColourPlugin } = require("@vulcancreative/cross-colour");

module.exports = {
  // ...
  plugins: [
    new CrossColourPlugin({
      sassFilename: path.resolve("src", "styles", "colours.scss"),
      jsFilename: path.resolve("src", "shared", "colours.js")
    }),
  ]
};

CrossColourPlugin accepts the following options:

| Option | Required | Default | Description | |--------------|----------|-----------|------------------------------------------------------------------------| | sassFilename | true | undefined | Absolute path to the (pre-existing) SASS/SCSS file. | | jsFilename | true | undefined | Absolute path to the (non-existent or pre-existing) JS output file. | | silent | false | false | If true, will not print when colours have been updated to the console. |

Library Use

Library use involves creating a CrossColours instance, and either passing it a configuration or passing the variables in imperatively.

import path from "path";
import { CrossColour } from "@vulcancreative/cross-colour";

const sassFilename = path.resolve("src", "styles", "colours.scss");
const jsFilename = path.resolve("src", "shared", "colours.js");

const cross = new CrossColour({ sassFilename, jsFilename, silent: true });

// simply read and write, based on config
cross.readWrite(); // or, if you hate yourself: cross.read().write();

// read to a JavaScript object and write to JS file in config
const obj = cross.colours();
cross.write(obj);

// manually write out somewhere that isn't specified in config
const silent = true; // defaults to false, if not passed
const elsewhere = path.resolve("elsewhere", "colours.js");
cross.write(obj, elsewhere, silent);

// aside from importing, you can also use the silly US spelling "colors"
const sillyUSObject = cross.colors();

License

MIT License

Copyright (c) 2020 Vulcan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.