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

@tlvk/yaml-to-scss

v1.0.0

Published

A simple command-line tool to convert YAML files into SCSS variables.

Downloads

6

Readme

yaml-to-scss

yaml-to-scss is a simple command-line tool to convert YAML files into SCSS files containing variables that are named based on the structure of the YAML file.

 

Contents

 

Installation

You can install yaml-to-scss via npm.

Install globally

npm i -g yaml-to-scss

Install as a dev-dependency

npm i -D yaml-to-scss

 

Usage

To convert a YAML file to a SCSS file, use the following command:

yaml-to-scss <src> <dest>

Replace <src> with the path to a YAML file and <dest> with the desired path for the resulting SCSS file.

 

If you didn't install yaml-to-scss globally or as a dev-dependency, you can use the following command:

npx yaml-to-scss <src> <dest>

 

The tool follows a simple convention for naming variables in SCSS:

  • Top-level keys in the YAML file become the basenames of the SCSS variables.
  • Nested keys are concatenated to the basename with a hyphen -.
  • Listed items get a number (starting from 0) concatenated to the basename with a hyphen -.
  • If the YAML key contains single or double quotes, they get converted to the SCSS file without changes.

You can find examples here!

Please also keep in mind that

  • The tool converts only one YAML file at a time.
  • Each conversion overwrites the contents of the SCSS file, erasing any previous content.

 

Examples

Basic Conversion

Consider you have a .yaml file with the following content:

primary: blue
secondary: gray
danger: red
success: green

Running yaml-to-sass on this YAML file will create a .scss file with the following content:

$primary: blue;
$secondary: gray;
$danger: red;
$success: green;

 

Converting Nested YAML

Consider you have a .yaml file with the following content:

theme:
  colors:
    primary: blue
    secondary: red
    background:
      default: white
      alternate: gray

Running yaml-to-sass on this YAML file will create a variables.scss file with the following content:

$theme-colors-primary: blue;
$theme-colors-secondary: red;
$theme-colors-background-default: white;
$theme-colors-background-alternate: gray

 

Converting Quoted Keys

Consider you have a .yaml file with the following content:

font-stacks:
  sans-serif: "Cambria, 'Hoefler Text', Utopia, 'Liberation Serif', Times, 'Times New Roman', serif"
  serif: "Constantia, 'Lucida Bright', Lucidabright, 'Lucida Serif', Lucida, 'Liberation Serif', Georgia, serif"
  monospace: "Consolas, 'Andale Mono WT', 'Andale Mono', 'DejaVu Sans Mono',  Monaco, 'Courier New', Courier, monospace"

Running yaml-to-sass on this YAML file will create a .scss file with the following content:

$font-stacks-sans-serif: "Cambria, 'Hoefler Text', Utopia, 'Liberation Serif', Times, 'Times New Roman', serif"
$font-stacks-serif: "Constantia, 'Lucida Bright', Lucidabright, 'Lucida Serif', Lucida, 'Liberation Serif', Georgia, serif"
$font-stacks-monospace: "Consolas, 'Andale Mono WT', 'Andale Mono', 'DejaVu Sans Mono',  Monaco, 'Courier New', Courier, monospace"

 

Converting Lists

Consider you have a list.yaml file with the following content:

list:
  - item: value1
  - item: value2
  - item: value3

Running yaml-to-sass on this YAML file will create a .scss file with the following content:

$list-0-item: value1;
$list-1-item: value2;
$list-2-item: value3;

 

License

This project is licensed under the MIT license.