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

@jabuco/typed-scss-modules

v0.2.0

Published

TypeScript type definition generator for SCSS CSS Modules

Downloads

4

Readme

🎁 typed-scss-modules

All Contributors 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

Run with npm package runner:

npx tsm src

Or, install globally:

yarn global add typed-scss-modules
tsm src

Or, install and run as a devDependency:

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

Advanced Usage

For all possible commands, run tsm --help.

The only required argument is the directoy 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

--logLevel (-v)

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

Set the Log verbosity to a certain level to regulate its output.

--watch (-w)

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

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

--watchTimeout (-t)

  • Type: number
  • Default: 50
  • Example: tsm --watchTimeout 250 src

Wait x miliseconds before writing the changes when watching. This is useful if file access is slow.

--ignoreInitial

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

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.

--includePaths (-i)

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

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.

--aliases (-a)

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

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 --aliasPrefixes.~ node_modules/ -- src

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 --nameFormat camel src

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 --listDifferent src

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 --exportType default src

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 interface 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.

Examples

For examples, see the examples directory:

Contributors ✨

Thanks goes to these wonderful people (emoji key):

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.