Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-to-ts

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-to-ts

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

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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

ArgumentTypeDefaultDescription
-h, --helpbooleanfalseShow help.
-v, --versionbooleanfalseShow current version.
--rootDirstring./Specifies the root directory of input files.
--outDirstring./Redirect output structure to the directory.
--outExtstringtsSpecifies extension of output TypeScript file.
--patternstring**/*.cssFiles glob pattern.
-w, --watchbooleanfalseWatch for changes of input files.
--prefixstringPrefix added to output file name.
--suffixstringSuffix added to output file name.
--delimiterstring-Specifies delimiter for prefix and suffix. Required if one of these are set.
--removeSourcebooleanfalseRemove all source files specified by glob pattern.
--headerstringSpecifies header comment in generated TS file.
--cwdstringprocess.cwd()Specifies current working directory.
--excludearray["**/node_modules/**"]Specifies an array of globs to exclude.
--varNamestringSpecifies name of variable to be exported in TypeScript file.
--varTypestringconstSpecifies 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";
ArgumentTypeRequiredDescription
stringifiedCssstring*Stringified css to be exported in TypeScript file.
variableNamestring*Name of variable to be exported in TypeScript file.
headerCommentstringComment placed in the top of exported TypeScript file.
varTypestringType 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 argumentTypeRequiredDescription
outputDirstring*Directory of output file.
outputFileNamestring*Name of output file.
cssDirstring*Directory of css file.
cssFileNamestring*File name of css file.
varNamestring*Name of variable to be exported in TypeScript file.
headerstringComment placed in the top of exported TypeScript file.
removeSourcebooleanShould css file be deleted after TypeScript file emitted.
varTypeVarTypeType of variable to be exported in TypeScript file.

License

Released under the MIT license.

Keywords

FAQs

Package last updated on 06 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc