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

json2scss-map

v1.5.1

Published

This is an utility tool for the developers to customizing colors, fonts & other whitelabel stuff and compiling into SCSS variable. So, anyone can change the look & feel of your app in just few steps.

Downloads

183

Readme

Contributors Forks Stargazers Issues MIT License LinkedIn

About The Project

Product Name Screen Shot

There are lots of Json-sass package available on npm; however, I didn't find one that really suited my needs. So, I thought of creating one. Altough, i find one that's good enough & made by Andrew Clark. But that wasn't maintained from last 6+ years.

This is an Utility module that converts a JSON stream into sass maps. It can be used as whitelabeling themes, fonts etc.

Here's why it's best:

  • firstly, you can share values between your scripts and stylesheets without having to use something like SassyJSON, which doesn't work with libsass.
  • json2scss-map converts JSON objects into Sass maps, which are supported in Ruby Sass 3.3 and libsass 2.0. & latest Dart Sass.
  • Also, New Version includes color convertions to HEX, HSL, RGB 😎

Built With

This is a very small package without any major dependency. However, we use some packages for giving support for browser-compatible Javascript, Unit testing etc.

Getting Started

It's very easy to use this plugin, instructions are mentioned below or you can View Demo.

Prerequisites

There no such basic requirements only node.js should be installed. also update npm or yarn if you can. Although, there are some issue in node 17.

Installation

There are many ways to install this plugin mentioned below.

  • using npm:
    npm i -D json2scss-map
  • using yarn:
    yarn add json2scss-map -D

Usage

Example source file theme.json:

Input Json

From the command-line:

$ json2scss-map -i theme.json -o theme.scss -p "\$variable: " -t hex

CLI Options:

  • -i, --infile: (Default: standard input stdin) Specify the input file.
  • -o, --outfile: (Default: standard output stdout) Designate the output SCSS file.
  • -p, --prefix: Set a prefix for all SCSS variables.
  • -s, --suffix: Set a suffix for all SCSS variables.
  • -c, --colorConversion: (Default: true) Enable or disable color conversion.
  • -t, --convertTo: (Default: 'hsl') Specify the color format (e.g., hsl, hex, rgb).
  • -l, --cl4Syntax: (Default: false) Use cl4 syntax if applicable.

Output theme.scss with new color convertion to hsl by default:

Output Scss map

Or you can use the Node API: (recommended)

var fs = require('fs');
var json2scss = require('json2scss-map');

fs.createReadStream('theme.json')
  .pipe(json2scss({
    prefix: '$variable: ',
    cl4Syntax: true
  }))
  .pipe(fs.createWriteStream('theme.scss'));

Then, you can get the values from scss:map

  $color-primary: map-get(map-get($variable, "theme"), "primary"); // hsl(211, 100%, 50%)
  $font-main: map-get($variable, "fs-main"); // "Mulish"

You can also transform normal JavaScript values using the exposed utility function:

json2scss.convertJs([1, 2, 3]); // (1, 2, 3)

For more, please refer to the View Demo

Alternatively, If you're using custom Webpack Configuration, you can use this tool to easily import JSON files and get the correct values. Json2scss-map-webpack-importer

API

json2scss([opts])

Returns a through stream. Available options:

  • prefix: Add some text to the beginning
  • suffix: Add some text to the end. Defaults to ';'.
  • colorConversion: New Feature to convert only colors value to different color scheme. Defaults to true. (from v1.5.0)
  • convertTo: Right now support convertion for HSL, RGB, HEX colors. Defaults to hsl.
  • cl4Syntax: color lavel 4 new syntax with space separator for the output. Defaults to false.

json2scss.convertJs(jsValue)

Convert a normal JavaScript value to its string representation in Sass. Ignores undefined and functions. Calls .toString() on non-plain object instances.

Roadmap

  • [x] Add Changelog
  • [x] Add new Color label 4 syntax support
  • [x] Add Color Convertion to (hsl, rgb, hex)
  • [ ] Add support for Color Lavel 4 Syntax in input stream as well.
  • [ ] Add Support for LCH color scheme convertion.
  • [ ] Add Support for % value in RGB colors.
  • [ ] Add Support for turn, deg, rad etc unit support in hsl & rgb colors.

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this plugin better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star ⭐️! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/{feature-name})
  3. Commit your Changes (git commit -m 'Add some {feature}')
  4. Push to the Branch (git push origin feature/{feature-name})
  5. Open a Pull Request
  6. You're awesome.

License

Distributed under the MIT License. See LICENSE for more information. AS Developers

Contact

Susanta Chakraborty - @susantaChak

Project Link: https://github.com/AS-Devs/json2scss-map

Acknowledgments

There are lots of people to acknowledge. I've included few of them to help be build this plugin.

Donate

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of :tea: