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

@egoistdeveloper/twcss-to-sass

v2.2.0

Published

HTML template to SASS converter for TailwindCSS

Downloads

36

Readme

twcss-to-sass

EgoistDeveloper twCss-to-sass

HTML template to SASS converter for TailwindCSS

CodeFactor NPM NPM Type Definitions NPM

About

There are many tailwind component sharing platforms, snippet websites, code pens, UI kits, etc. We generally see static demos and inline class lists like <div class="text-base leading-6 text-gray-500 hover:text-gray-900">.... If you want to choose the SASS option for your project, you need to convert inline classes and templates one by one. And this process takes time. This tool converts inline class lists to SASS and it takes just milliseconds.

This tool is useful for a quick start but all cases did not consider. There are many edge cases. So, you may need to refactor output HTML and SASS results.

🚀 Playground

Use converter playground for quick start.

📦 Installation

NPM

npm i @egoistdeveloper/twcss-to-sass

CDN

<script src="https://unpkg.com/@egoistdeveloper/twcss-to-sass@latest/dist/umd/index.js"></script>

Todo

  • [x] Fix missing texts with child element
  • [x] Fix self-closing tags like link, base, area, br etc
  • [x] Fix url conflict with class name in comment line
  • [x] Add option for duplicated classes
  • [x] Fix group and peer utility classes issue on SASS
  • [ ] Filter non tailwind classes
  • [x] Order classes
  • [x] Group classes
  • [ ] Print as group classes
  • [x] Add configs menu for playground
  • [ ] Detect tailwind classes

Input-Output

Template Input

<!-- Container Start -->
<div class="bg-white">
	<!-- Some Div -->
	<div class="flex justify-center items-center min-h-screen min-w-full">
		<div class="flex relative">
			<!-- Inner Div -->
			<div class="w-72 h-40 bg-green-400 transform transition-all">
				My Text 1
			</div>
		</div>
	</div>
</div>
<!-- Container End-->

HTML Output

<!-- Container Start -->
<div class="container-start">
    <!-- Some Div -->
    <div class="some-div">
        <div class="class-div-3">
            <!-- Inner Div -->
            <div class="inner-div">
                My Text 1
            </div>
        </div>
    </div>
</div>

SASS Output

/* Container Start -> 1 */
.container-start {
    @apply bg-white;

    /* Some Div -> 2 */
    .some-div {
        @apply flex items-center justify-center min-h-screen min-w-full;

        /* div -> 3 */
        .class-div-3 {
            @apply flex relative;

            /* Inner Div -> 4 */
            .inner-div {
                @apply bg-green-400 h-40 transform transition-all w-72;
            }
        }
    }
}

🔰 Browser Example

<!-- local -->
<script src="./../../dist/umd/index.js"></script>

<!-- or -->

<!-- CDN -->
<script src="https://unpkg.com/@egoistdeveloper/twcss-to-sass@latest/dist/umd/index.js"></script>

<script>
    const { convertToSass } = TwCssToSass,
    html = `<!-- Container Start -->
            <div class="bg-white">
              <!-- Some Div -->
              <div class="flex justify-center items-center min-h-screen min-w-full">
                <div class="flex relative">
                  <!-- Inner Div -->
                  <div class="w-72 h-40 bg-green-400 transform transition-all">
                    My Text 1
                  </div>
                </div>
              </div>
            </div>
            <!-- Container End-->`;

    console.log(convertToSass(html).html);
    console.log(convertToSass(html).sass);
</script>

🔰 NodeJS Example

const TwCssToSass = require('./twcss-to-sass');
const path = require('path');
const fs = require('fs');

const htmlContent = fs.readFileSync(
  path.resolve(__dirname, './templates/template-1.html'),
  'UTF-8'
)

console.log(TwCssToSass.convertToSass(htmlContent).html);
console.log(TwCssToSass.convertToSass(htmlContent).sass);

🔰 Angular, React, Vue, etc...

import { convertToSass } from '@egoistdeveloper/twcss-to-sass';

const htmlContent = '<div class="w-72 h-40 bg-green-400 transform transition-all">My Text 1</div>';

console.log(convertToSass(htmlContent).html);
console.log(convertToSass(htmlContent).sass);

Attribution

Wind icons created by smalllikeart - Flaticon