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

@guyn/convert

v1.5.1

Published

Convert Colors into multiple files

Downloads

16

Readme

@Guyn/convert

A color convert to different formats. Format your JSON based source file to any file you want.

Installation

Installation isn't necessary, the script can be used through npx.

npx @guyn/convert --src mySourceFile.json --dest /temp --type scss

But if you really want it in your project, you can install it using npm;

npm install guyner

or Yarn;

yarn add guyner

Arguments

| Argument | Required | Options | Description | | ------------ | --------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --src | ✔ | file / path string | The source file (json) or folder (with json files) for your colors | | --dest | ✔ | file / path string | Destination folder of the generated files. | | --type | × (only if template is not set) | scss, less, css, json, js, yaml | The output type of file to be used. | | --template | × (only if type is not set) | string | A template file or folder with files to use to generate the files. When the provided templates arent sufficient | | --advanced | × | hsla, rgba | Add more output types to the files. | | --prefix | × | boolean | A prefix will be used within the fixes to prefix variables or objects | | --combine | × | boolean | When given multiple sources, they can be combined into one output file | | --filename | × | string | You can give an altername output name for your file. They will use they extension of your template. When given multiple destinations (not combined) you need to give the same amount of filenames | | --title | × | string | The Set name used in the procreate file. For now this is only need when you generate Procreate swatches |

Usage

@guyn/convert can be used as a npx script or as a node_module in your package. The easiest way is to install it and use it in a script in your package.json like;

// package.json
{
	"scripts": {
		"convert-colors": "guyner --src assets/my-colors.json --dest src/assets/scss/ --type scss"
	}
}

You could also, due to the total amount of arguments which could be big, create a bash script which can be ran by the scripts.

// package.json
{
	"scripts": {
		"convert-colors": "sh scripts/colors.sh"
	}
}
echo "> 01: Create a SCSS file from source"
npx guyner \
     --src assets/my-colors.json \
     --dest src/assets/scss/ \
     --type scss
     --type css

Custom templates

Besides the templates already made which can be used easily. You an also define your own template. Templates are using the ejs template syntax.

Examples can be found in the /templates folder of this package.

Example of the css template;


:root{
<% var i=0; Object.keys(colors).forEach(function(color){ i++; %>
--<%= settings.prefix %><%= colors[color].name %>: <%= colors[color].hex %>;
--<%= settings.prefix %><%= colors[color].name %>-hue: <%= colors[color].hsl.h %>;
--<%= settings.prefix %><%= colors[color].name %>-saturation: <%= colors[color].hsl.s %>;
--<%= settings.prefix %><%= colors[color].name %>-lightness: <%= colors[color].hsl.l %>;
--<%= settings.prefix %><%= colors[color].name %>-red: <%= colors[color].rgb.r %>;
--<%= settings.prefix %><%= colors[color].name %>-green: <%= colors[color].rgb.g %>;
--<%= settings.prefix %><%= colors[color].name %>-blue: <%= colors[color].rgb.b %>;
<% }); %>
}

Procreate Swatches

Convert can also create Procreate swatch files in the same matter as it does any other files. For this you will need to add a title and make sure you set a output file;

In package json script;

package.json

...
	"build:procreate": "guyn@convert --src src/yourfile.json --dest dist/Yourfile.swatches --title Yourfile --type procreate
...

In a shell file;

Or on a bash file (procreate.sh);

package.json

...
	"build:procreate": "node scripts/procreate.sh"
...

scripts/procreate.sh

node node_modules/guyn/convert/dist/cli.js \
    --src test/source/valid/source1.json \
    --dest tmp/01-procreate/Test.swatches \
    --title GuynTest \
    --type procreate \

Wishlist

  • Add support for rgba, hsla and 3 digix colors.
  • Add option to be able to use depth in source files.

Contributing

Any help to make this package better is very welcome! So if you like this idea and have a good idea for refactor, update, write better docs or add features. Please feel free to contact me or just make a PR.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

guyner © Sil van Diepen, Released under the MIT License. Authored and maintained by Sil van Diepen with help from contributors (list).

github.com/silvandiepen · GitHub @Sil van Diepen · Twitter @silvandiepen