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

stylus-converter

v0.8.1

Published

A tool that converts a stylus into sass, or less, or other precompiled CSS.

Downloads

571

Readme

What is this

A tool that converts a stylus into scss, or less, or other precompiled CSS.

stylus-converter config

converter options

| Attribute | Description | Type | Accepted Values | Default | | ---- | ---- | ---- | ---- | ---- | | quote | The quote type to use when converting strings | string | ' / " | ' | | conver | Conversion type, such as conversion to scss syntax | string | scss | scss | | autoprefixer | Whether or not to automatically add a prefix, stylus will automatically add prefixes when converting stylus grammars. @keyframes | boolean | true / false | true | | indentVueStyleBlock | Indent the entire style block of a vue file with a certain amount of spaces. | number | number | 0 |

cli options

| Attribute | Shorthand | Description | Accepted Values | Default | | ---- | ---- | ---- | ---- | ---- | | --quote | -q | The quote type to use when converting strings | single / dobule | single | | --input | -i | Enter a name, which can be a path to a file or a folder | - | - | | --output | -o | Output name, can be a path to a file or a folder | - | - | | --conver | -c | Conversion type, such as conversion to scss syntax | scss | scss | | --directory | -d | Whether the input and output paths are directories | yes / no | no | | --autoprefixer | -p | Whether to add a prefix | yes / no | yes | | --indentVueStyleBlock | -v | Indent the entire style block of a vue file with a certain amount of spaces. | number | 0 |

How to handle single line comments

1. First fork project and then clone project to local
git clone [email protected]:<your github>/stylus-converter.git

2. Enter the project directory
cd stylus-converter

3. Installation project depends
npm install

4. Go to line 581 of the `node_modules/stylus/lib/lexer.js` file.

5. Modify the code below.
// before modification
if ('/' == this.str[0] && '/' == this.str[1]) {
  var end = this.str.indexOf('\n');
  if (-1 == end) end = this.str.length;
  this.skip(end);
  return this.advance();
}

// After modification
if ('/' == this.str[0] && '/' == this.str[1]) {
  var end = this.str.indexOf('\n');
  const str = this.str.substring(0, end)
  if (-1 == end) end = this.str.length;
  this.skip(end);
  return new Token('comment', new nodes.Comment(str, suppress, true))
}

Use examples

// download stylus-converter
npm install -g stylus-converter

// Run the cli conversion file
stylus-conver -i test.styl -o test.scss

// Run the cli conversion directory
// cd your project
mv src src-temp
stylus-conver -d yes -i src-temp -o src

Conversion file comparison

Stylus source code before conversion

handleParams(args...)
  args

@media screen and (max-width: 500px) and (min-width: 100px), (max-width: 500px) and (min-height: 200px)
  .foo
    color: #100

.foo
  for i in 1..4
    @media (min-width: 2 * (i + 7) px)

Converted SCSS source code

@function handleParams($args...) {
  @return $args;
}

@media screen and (max-width: 500px) and (min-width: 100px), (max-width: 500px) and (min-height: 200px) {
  .foo {
    color: #100;
  }
}

.foo {
  @for $i from 1 through 4 {
    @media (min-width: 2 * ($i + 7) px) {
      width: 100px * $i;
    }
  }
}

If you do not want to add the default prefix for your converted @keyframes, please set options.autoprefixer = false

The .vue file before conversion

<template>
  <div class="page-home">
    <el-button>click me</el-button>
  </div>
</template>

<style lang="stylus">
.page-home
  .el-button
    margin: 10px auto
</style>

Converted .vue file

<template>
  <div class="page-home">
    <el-button>click me</el-button>
  </div>
</template>

<style lang="scss">
.page-home {
  .el-button {
    margin: 10px auto;
  }
}
</style>

Build a development environment

1. First fork project and then clone project to local
git clone [email protected]:<your github>/stylus-converter.git

2. Enter the project directory
cd stylus-converter

3. Installation project depends
npm install

4. Package compilation source file
npm run build

5. Local debugging cli
npm link