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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@navaru/css

v1.1.3

Published

CSS modules

Downloads

9

Readme

@navaru/css

CSS Modules are files in which all class names are scoped locally by default, this fixes the problem of global scope in CSS.

Example

import CSSModules from '@navaru/css'

const css = CSSModules()
const { exports } = css.load('./example/basic/index.css')

// exports.box == '_basic_index_box'
const html = `
  <div class="${ exports.box }">some content</div>
`

// get the loaded bundle
const bundle = css.bundle()

APIs

import CSSModules from '@navaru/css'

const css = CSSModules(options)

Options:

  • resolve(request, from) - resolve the
    • request - the requested import from: @import name from 'request'
    • from (optional) - the folder name from which the request is made
  • setName(name, file) - generates the class names
    • defaults to _${folder}_${filename}_${classname}
    • name - the CSS class name

CSS module object format:

  • path — the file path
  • source — the source file contents
  • ast — the CSS abstract syntax tree
  • imports — the imported class names
  • local — an object containing class names and generated names
  • exports — an object containing class names and generated names plus composed values

css.load(path, type)

Parses source code and returns a module object.

  • path - CSS file path
  • type - CSS Module type, raw or module (optional)
const cssModule = css.load('./file.css')

css.bundle()

Return the CSS bundled source.

const source = css.bundle()

css.use(plugin)

Plugins allow you to customise the format and output of a CSS module.

  • plugin - a plugin function with the following format (module, bundler) => {}
const logAST = (module, css) => {
  console.log(module.ast)
}

css.use(logAST)

css.parse(options)

  • file - absolute file path
  • source - CSS source string
  • type - raw or module
    • module - will parse the file generating class names and exporting values
    • raw - will load the CSS file as is, not generating class names, useful when bundling 3rd party CSS files

Loads a CSS file and returns an object module containing

const cssModule = css.parse({
  file: '/path/to/file.css',
  source: 'body { background: white }',
  type: 'raw',
})

Specifications

Importing styles

Include all styles into bundle, parsing and generating class names:

@import from './file.css';

Import class names into local scope, prefixed with base :

@import * as base from './base.css';

.iconButton {
  compose: base.button;
}

Import specific class names into local scope:

@import button, icon from './base.css';

.button_icon {
  compose: button, icon;
}

Import a file as is, without parsing its content, designed for bundling external resources.

@import raw './some_library_styles.css';

Composition

Declaration compose composes parent class name with the provided class names.

theme.css

.icon {
  border: 1px solid #999999;
  width: 2em;
  height: 2em;
}

index.css

@import icon from './theme.css';

.button {
  border: 1px solid #DEDEDE;
}

.button_icon {
  compose: button, icon;
  font-size: .875em;
}

index.js

import style from './style.css'

style.button_icon == '.button_icon .button .icon'

License ISC