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

cssobj-plugin-localize

v3.3.2

Published

Localize class name for cssobj

Downloads

14

Readme

cssobj-plugin-localize

Join the chat at https://gitter.im/css-in-js/cssobj Build Status

Localize class names for cssobj. Put CSS Class names into different name space.

Install

install from github directly:

npm install cssobj/cssobj-plugin-localize

API

localize(space: boolean|string, localNames: object) -> {selector: function}

space

  • Type: String | Boolean

  • Default: Random String

If pass empty string '', will use '' (empty space)

If pass other falsy value, will use default.

localNames

  • Type: Object

  • Default: {}

key/val pair to define how class name map into local name.

Key is original class name.

Val is localized name.

RETURN

Add method to result

The cssobj result object will be added 2 method by this plugin:

- result.mapSel({string} selector){ return {string} mappedSelector }

Replace class names in selector string, with all class names replace by localized version. (keep dot .)

- result.mapClass({string} classList){ return {string} mappedClassList }

Treat classList string as space seperated class list(e.g. in <div class="abc efg">),

Replace all seperated word by localized version. (without dot)

The classList can be 'nav item', or '.nav .item' form, all . will be replaced by space.

The returned class string is .trim()ed, you need polyfill this method if you want support IE < 9.

Above 2 method both can accept .!class1 .!class2 escaped for global space.

Usage

- Localize

var localize = require('cssobj-plugin-localize')
var ret = cssobj({'.item': {color: 'red'}}, {
  plugins:[  localize() ]
})
// css is => ._1hisnf23_item {color: red;}

// you can get the mapped selector using:
ret.mapSel('.nav .item')  // === ._1hisnf23_nav ._1hisnf23_item

// you can get the mapped class list using:
// (used in className attributes for HTML tag)
ret.mapClass('.nav .item')  // === _1hisnf23_nav _1hisnf23_item
ret.mapClass('nav item')  // === _1hisnf23_nav _1hisnf23_item

- Global

There's a way to make class Global

- .!className

Just add ! in front of class name, if you want it global.

var ret = cssobj({'body .!nav .!item .login': {color: 'red'}}, {
  plugins:[  localize() ]
})
// css is => body .nav .item ._1hisnf23_login {color: red;}

- Custom Prefix

You can control the space:

var ret = cssobj({'body .nav .item .login': {color: 'red'}}, {
  plugins:[  localize('_your_space_') ]
})
// css is => body ._your_space_nav ._your_space_item ._your_space_login {color: red;}

- Custom Local Names

You can control the map for each class name:

var ret = cssobj({'body .nav .!item .login': {color: 'red'}}, {
  plugins:[  localize(null, {nav: '_abc_'}) ]
})
// css is => body ._abc_ .!item ._1hisnf23_login {color: red;}

- Get the class map

var ret = cssobj({'body .nav .item .login': {color: 'red'}}, {
  plugins:[  localize('_space_', {nav: '_abc_'}) ]
})

ret.mapSel('.nav .item .!pushRight')  // === ._abc_ ._space_item .pushRight
ret.mapSel('.!nav .!item .pushRight')  // === .nav .item ._space_pushRight
ret.mapClass('item nav !pushRight')  // ===  _space_item _abc_ pushRight