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

css-to-ts

v1.0.1

Published

css-to-ts takes a css file and outputs a TypeScript file with an exported string containing a content of your css file.

Downloads

3,241

Readme

css-to-ts

Compiles css files to importable TypeScript files.

Installation

npm install css-to-ts -g

Global installation is not necessary. You can install this package with:

npm install css-to-ts

and use it with npm-scripts.

Features

  • Takes css files and output TypeScript files with exported string containing content of your css file.
  • CLI tool for watching and files compilation.
  • Works with node-glob pattern.

Command line

Usage

css-to-ts -h

Arguments

| Argument | Type | Default | Description | |-------------------------------|-----------|---------------------------|-------------------------------------------------------------------------------| | -h, --help | boolean | false | Show help. | | -v, --version | boolean | false | Show current version. | | --rootDir | string | ./ | Specifies the root directory of input files. | | --outDir | string | ./ | Redirect output structure to the directory. | | --outExt | string | ts | Specifies extension of output TypeScript file. | | --pattern | string | **/*.css | Files glob pattern. | | -w, --watch | boolean | false | Watch for changes of input files. | | --prefix | string | | Prefix added to output file name. | | --suffix | string | | Suffix added to output file name. | | --delimiter | string | - | Specifies delimiter for prefix and suffix. Required if one of these are set. | | --removeSource | boolean | false | Remove all source files specified by glob pattern. | | --header | string | | Specifies header comment in generated TS file. | | --cwd | string | process.cwd() | Specifies current working directory. | | --exclude | array | ["**/node_modules/**"] | Specifies an array of globs to exclude. | | --varName | string | | Specifies name of variable to be exported in TypeScript file. | | --varType | string | const | Specifies type of variable to be exported in TypeScript file. |

Example

css-to-ts --rootDir "./src" --outDir "./dist" --pattern "*.css" --header "File generated with css-to-ts"

Input file ./src/orange.css:

.orange {
    color: orange;
    border: 1px solid yellow;
}

Generated ./dist/orange.ts:

// File generated with css-to-ts
export const Orange = `.orange {
    color: orange;
    border: 1px solid yellow;
}`;

API

ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string, varType: VarType = VarType.Const): string

Takes stringified css and outputs TypeScript code with exported string containing content of your css file.

Usage:

import { ConvertCssToTs } from "css-to-ts";

| Argument | Type | Required | Description | |-------------------|--------|----------|-----------------------------------------------------------| | stringifiedCss | string | * | Stringified css to be exported in TypeScript file. | | variableName | string | * | Name of variable to be exported in TypeScript file. | | headerComment | string | | Comment placed in the top of exported TypeScript file. | | varType | string | | Type of variable to be exported in TypeScript file. |

export enum VarType {
    Var = "var",
    Let = "let",
    Const = "const"
}

new CssToTsConverter(outputDir, outputFileName, cssDir, cssFileName, varName, header, removeSource, varType)

Compiles css files to importable TypeScript files.

Usage:

import { CssToTsConverter } from "css-to-ts";

const converter = new CssToTsConverter(
    outputDir,
    outputFileName,
    cssDir,
    cssFileName,
    varName,
    header,
    removeSource
);

try {
    await converter.Convert();
} catch(error) {
    console.error(error);
}

| Constructor argument | Type | Required | Description | |-----------------------|-----------|-----------|---------------------------------------------------------------| | outputDir | string | * | Directory of output file. | | outputFileName | string | * | Name of output file. | | cssDir | string | * | Directory of css file. | | cssFileName | string | * | File name of css file. | | varName | string | * | Name of variable to be exported in TypeScript file. | | header | string | | Comment placed in the top of exported TypeScript file. | | removeSource | boolean | | Should css file be deleted after TypeScript file emitted. | | varType | VarType | | Type of variable to be exported in TypeScript file. |

License

Released under the MIT license.