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

css-to-ts

Package Overview
Dependencies
Maintainers
1
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 css file and outputs TypeScript file with an exported string containing content of your css file.

  • 0.1.0-beta.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
818
increased by27.61%
Maintainers
1
Weekly downloads
 
Created
Source

css-to-ts

Compiles css files to importable TypeScript files.

Instalation

$ npm install css-to-ts -g

Global installation is not necessary. You can install this package with sh $ npm install css-to-ts and use it in 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.
--patternstring**/*.cssFiles glob pattern.
-w, --watchbooleanfalseWatch for changes of input files.
--prefixstringPrefix added to ouput file name.
--suffixstringSuffix added to output file name.
--delimitterstring-Specifies delimitter 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.

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 var Orange = `.orange {
    color: orange;
    border: 1px solid yellow;
}`;

API

ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string): 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.

new CssToTsConverter(tsDir, tsFileName, cssDir, cssFileName, varName, header, removeSource)

Compiles css files to importable TypeScript files.

Usage:

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

const converter = new CssToTsConverter(
    tsDir,
    tsFileName,
    cssDir,
    cssFileName,
    varName,
    header,
    removeSource
);

try {
    await converter.Convert();
} catch(error) {
    console.error(error);
}
Constructor argumentTypeRequiredDescription
tsDirstring*Directory of TypeScript file.
tsFileNamestring*File name of TypeScript 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 emmitted.

License

Released under the MIT license.

Keywords

FAQs

Package last updated on 12 Apr 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