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

postcss-js-core

v0.5.1

Published

The core module of various postcss css-in-js syntaxes

Downloads

9,557

Readme

postcss-js-core

postcss-js-core provides common functionality needed by various css-in-js custom PostCSS syntaxes.

Many css-in-js syntaxes do much of the same work, with slight variations on what they support and how they work. This module aims to provide the basic building blocks for those situations.

Usage

Let's say your syntax makes use of tagged template literals named css.

You can create your PostCSS syntax like so:

import {
  createParser,
  createStringifier
} from 'postcss-js-core';

const options = {
  id: 'my-syntax',
  tagNames: ['css']
};

export = {
  parse: createParser(opts),
  stringify: createStringifier(opts)
};

If you then use this as a PostCSS/stylelint custom syntax, it will parse the following code:

const foo = css`
  div { color: blue; }
`;

Options

When creating a parser/stringifier, you can specify some options. These are as follows:

{
  // Required - an identifier for your syntax
  id: 'my-syntax',

  // Tagged templates to look for
  tagNames: ['css'],

  // Custom sub-parser
  parser: lessSyntax.parse,

  // Custom sub-stringifier _class_
  stringifier: require('postcss-less/lib/LessStringifier.js')
}

Tag names

We currently only support CSS in tagged template literals. The tags we consider as stylesheets are specified by tagNames in the options object.

Any tagged templates using these names will have their contents treated as CSS and extracted into PostCSS.

Two forms are supported:

  • Exact tag names (e.g. ['css'])
  • Tag name prefixes (e.g. ['css.*'] would match css.foo, it is not a RegExp)

Sub-syntax

You may want to support a "syntax within a syntax". For example, LESS sources inside your JavaScript files.

In order to do this, you must pass the syntax's parser and stringifier class in your options.

For example:

createParser({
  // ...
  parser: require('postcss-less').parse,
  stringifer: require('postcss-less/lib/LessStringifier.js')
});

Importantly, you must pass the class of the stringifier rather than the stringify function. This is so we can correctly extend it.

Two common ones are (at time of writing this) located at:

  • SCSS - postcss-scss/lib/scss-stringifier.js
  • LESS - postcss-less/lib/LessStringifier.js