All Projects โ†’ skovy โ†’ Typed Scss Modules

skovy / Typed Scss Modules

Licence: mit
๐ŸŽ Generate type definitions (.d.ts) for CSS Modules using SCSS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Typed Scss Modules

Rollup Plugin Styles
๐ŸŽจ Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: โœญ 116 (-39.58%)
Mutual labels:  scss, sass, css-modules
Generator Ngx Rocket
๐Ÿš€ Extensible Angular 11+ enterprise-grade project generator
Stars: โœญ 1,329 (+592.19%)
Mutual labels:  cli, generator, sass
Css Vars
Sass mixin to use CSS Custom Properties with Sass
Stars: โœญ 164 (-14.58%)
Mutual labels:  scss, sass
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: โœญ 165 (-14.06%)
Mutual labels:  sass, css-modules
Browser Hack Sass Mixins
Browser hack sass mixin - Apply your SCSS to a specific browser - CSS hacks for: IE, Chrome, Firefox, Edge, Opera
Stars: โœญ 170 (-11.46%)
Mutual labels:  scss, sass
Cgx
๐Ÿ’ป๐Ÿ”ฅCLI to generate the recommended documentation/files to improve contribution (Github, Gitlab, CodeCommit and Bitbucket)
Stars: โœญ 190 (-1.04%)
Mutual labels:  cli, generator
React Timelines
React Timelines Library
Stars: โœญ 161 (-16.15%)
Mutual labels:  scss, sass
Compile Hero
๐Ÿ”ฐVisual Studio Code Extension For Compiling Language
Stars: โœญ 169 (-11.98%)
Mutual labels:  scss, sass
Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: โœญ 152 (-20.83%)
Mutual labels:  cli, generator
Buttons
A collection of CSS buttons.
Stars: โœญ 177 (-7.81%)
Mutual labels:  scss, sass
Frontplate
ใƒ•ใƒญใƒณใƒˆใ‚จใƒณใƒ‰้–‹็™บใฎๅŠน็Ž‡ใ‚’ใ‚ใ’ใ‚‹ใƒ•ใƒซใ‚นใ‚ฟใƒƒใ‚ฏใƒ†ใƒณใƒ—ใƒฌใƒผใƒˆ
Stars: โœญ 175 (-8.85%)
Mutual labels:  scss, sass
Sass Extras
Useful utilities for working with Sass
Stars: โœญ 179 (-6.77%)
Mutual labels:  scss, sass
Kindling
A pocket-sized grid system built on the flex display property.
Stars: โœญ 155 (-19.27%)
Mutual labels:  scss, sass
Faviator
A simple easy favicon generator.
Stars: โœญ 155 (-19.27%)
Mutual labels:  cli, generator
Include Media
๐Ÿ“ Simple, elegant and maintainable media queries in Sass
Stars: โœญ 2,362 (+1130.21%)
Mutual labels:  scss, sass
Flexible Grid
Flexible grid layouts to get you familiar with building within the flexible grid system.(HTML, CSS, SASS, SCSS)
Stars: โœญ 154 (-19.79%)
Mutual labels:  scss, sass
Sassessentials
Repository for my tutorial course: Sass Essential Training on LinkedIn Learning and Lynda.com.
Stars: โœญ 167 (-13.02%)
Mutual labels:  scss, sass
Iota
A responsive micro-framework for the grid spec powered by CSS custom properties.
Stars: โœญ 189 (-1.56%)
Mutual labels:  scss, sass
Skeleton Sass
Skeleton Sass is a highly modular version of Skeleton CSS
Stars: โœญ 151 (-21.35%)
Mutual labels:  scss, sass
React Native Sass Transformer
Use Sass to style your React Native apps.
Stars: โœญ 151 (-21.35%)
Mutual labels:  scss, sass

๐ŸŽ typed-scss-modules

Build Status npm version

Generate TypeScript definitions (.d.ts) files for CSS Modules that are written in SCSS (.scss). Check out this post to learn more about the rationale and inspiration behind this package.

Example

For example, given the following SCSS:

@import "variables";

.text {
  color: $blue;

  &-highlighted {
    color: $yellow;
  }
}

The following type definitions will be generated:

export const text: string;
export const textHighlighted: string;

Basic Usage

Install and run as a devDependency:

yarn add -D typed-scss-modules
yarn tsm src

Or, install globally:

yarn global add typed-scss-modules
tsm src

Or, with npm:

npm install -D typed-scss-modules
./node_modules/.bin/tsm src

Advanced Usage

For all possible commands, run tsm --help.

The only required argument is the directory where all SCSS files are located. Running tsm src will search for all files matching src/**/*.scss. This can be overridden by providing a glob pattern instead of a directory. For example, tsm src/*.scss

--watch (-w)

  • Type: boolean
  • Default: false
  • Example: tsm src --watch

Watch for files that get added or are changed and generate the corresponding type definitions.

--ignoreInitial

  • Type: boolean
  • Default: false
  • Example: tsm src --watch --ignoreInitial

Skips the initial build when passing the watch flag. Use this when running concurrently with another watch, but the initial build should happen first. You would run without watch first, then start off the concurrent runs after.

--ignore

  • Type: string[]
  • Default: []
  • Example: tsm src --watch --ignore "**/secret.scss"

A pattern or an array of glob patterns to exclude files that match and avoid generating type definitions.

--includePaths (-i)

  • Type: string[]
  • Default: []
  • Example: tsm src --includePaths src/core

An array of paths to look in to attempt to resolve your @import declarations. This example will search the src/core directory when resolving imports.

--implementation

  • Type: "node-sass" | "sass"
  • Default: If an option is passed, it will always use the provided package implementation. If an option is not passed, it will first check if node-sass is installed. If it is, it will be used. Otherwise, it will then check if sass is installed. If it is, it will be used. Finally, falling back to node-sass if all checks and validations fail.
  • Example: tsm src --implementation sass

--aliases (-a)

  • Type: object
  • Default: {}
  • Example: tsm src --aliases.~some-alias src/core/variables

An object of aliases to map to their corresponding paths. This example will replace any @import '~alias' with @import 'src/core/variables'.

--aliasPrefixes (-p)

  • Type: object
  • Default: {}
  • Example: tsm src --aliasPrefixes.~ node_modules/

An object of prefix strings to replace with their corresponding paths. This example will replace any @import '~bootstrap/lib/bootstrap' with @import 'node_modules/bootstrap/lib/bootstrap'. This matches the common use-case for importing scss files from node_modules when sass-loader will be used with webpack to compile the project.

--nameFormat (-n)

  • Type: "camel" | "kebab" | "param" | "dashes" | "none"
  • Default: "camel"
  • Example: tsm src --nameFormat camel

The class naming format to use when converting the classes to type definitions.

  • camel: convert all class names to camel-case, e.g. App-Logo => appLogo.
  • kebab/param: convert all class names to kebab/param case, e.g. App-Logo => app-logo (all lower case with '-' separators).
  • dashes: only convert class names containing dashes to camel-case, leave others alone, e.g. App => App, App-Logo => appLogo. Matches the webpack css-loader camelCase 'dashesOnly' option.
  • none: do not modify the given class names (you should use --exportType default when using --nameFormat none as any classes with a - in them are invalid as normal variable names). Note: If you are using create-react-app v2.x and have NOT ejected, --nameFormat none --exportType default matches the class names that are generated in CRA's webpack's config.

--listDifferent (-l)

  • Type: boolean
  • Default: false
  • Example: tsm src --listDifferent

List any type definition files that are different than those that would be generated. If any are different, exit with a status code 1.

--exportType (-e)

  • Type: "named" | "default"
  • Default: "named"
  • Example: tsm src --exportType default

The export type to use when generating type definitions.

named

Given the following SCSS:

.text {
  color: blue;

  &-highlighted {
    color: yellow;
  }
}

The following type definitions will be generated:

export const text: string;
export const textHighlighted: string;

default

Given the following SCSS:

.text {
  color: blue;

  &-highlighted {
    color: yellow;
  }
}

The following type definitions will be generated:

export type Styles = {
  text: string;
  textHighlighted: string;
};

export type ClassNames = keyof Styles;

declare const styles: Styles;

export default styles;

This export type is useful when using kebab (param) cased class names since variables with a - are not valid variables and will produce invalid types or when a class name is a TypeScript keyword (eg: while or delete). Additionally, the Styles and ClassNames types are exported which can be useful for properly typing variables, functions, etc. when working with dynamic class names.

--exportTypeName

  • Type: string
  • Default: "ClassNames"
  • Example: tsm src --exportType default --exportTypeName ClassesType

Customize the type name exported in the generated file when --exportType is set to "default". Only default exports are affected by this command. This example will change the export type line to:

export type ClassesType = keyof Styles;

--exportTypeInterface

  • Type: string
  • Default: "Styles"
  • Example: tsm src --exportType default --exportTypeInterface IStyles

Customize the interface name exported in the generated file when --exportType is set to "default". Only default exports are affected by this command. This example will change the export interface line to:

export type IStyles = {
  // ...
};

--quoteType (-q)

  • Type: "single" | "double"
  • Default: "single"
  • Example: tsm src --exportType default --quoteType double

Specify a quote type to match your TypeScript configuration. Only default exports are affected by this command. This example will wrap class names with double quotes ("). If Prettier is installed and configured in the project, it will be used and is likely to override the effect of this setting.

--updateStaleOnly (-u)

  • Type: boolean
  • Default: false
  • Example: tsm src --updateStaleOnly

Overwrite generated files only if the source file has more recent changes. This can be useful if you want to avoid extraneous file updates, which can cause watcher processes to trigger unnecessarily (e.g. tsc --watch).

Caveat: If a generated type definition file is updated manually, it won't be re-generated until the corresponding scss file is also updated.

--logLevel (-L)

  • Type: "verbose" | "error" | "info" | "silent"
  • Default: "verbose"
  • Example: tsm src --logLevel error

Sets verbosity level of console output.

verbose

Print all messages

error

Print only errors

info

Print only some messages

silent

Print nothing

--banner

  • Type: string
  • Default: undefined
  • Example: tsm src --banner '// This is an example banner\n'

Will prepend a string to the top of your output files

// This is an example banner
export type Styles = {
  // ...
};

Examples

For examples, see the examples directory:

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Janeene Beeforth

๐Ÿ› ๐Ÿ’ป ๐Ÿ“–

Eric Ferreira

๐Ÿ’ป ๐Ÿ“–

Luis Lopes

๐Ÿ’ป

Josh Wedekind

๐Ÿ’ป ๐Ÿ“– โš ๏ธ

Jared Gesser

๐Ÿค”

Raphaรซl L

๐Ÿ’ป ๐Ÿค”

Nick Perez

๐Ÿ› ๐Ÿ’ป

Even Alander

๐Ÿ’ป โš ๏ธ ๐Ÿค”

Katie Foster

๐Ÿ’ป โš ๏ธ ๐Ÿ“–

Carlos Aguilera

๐Ÿ’ป

Craig McCown

๐Ÿค” ๐Ÿ’ป โš ๏ธ ๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Alternatives

This package was heavily influenced on typed-css-modules which generates TypeScript definitions (.d.ts) files for CSS Modules that are written in CSS (.css).

This package is currently used as a CLI. There are also packages that generate types as a webpack loader.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].