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 🙏

© 2025 – Pkg Stats / Ryan Hefner

v-namespace

v1.0.1

Published

Adds custom prefix to all class declarations within v-namespace blocks for your CSS/SCSS files

Readme

v-namespace

Adds custom prefix to all class declarations within v-namespace blocks for your CSS/SCSS files/strings.

var doPrefix = require("v-namespace");
var css = `
    @include v-namespace('some-custom-prefix-') {
        .comp {
            color:black;
            .btn {
                color:white;
            }
            .a.b { color:red; }
        }
    }
`;
css = doPrefix(css);

Mainly used for distributing css-skinnable (but having completely self-contained base css styles) modular components anywhere (with a specific namespace) and providing a way of ensuring it's css class declarations will not be affected by any holding global/parenting css class names you may end up using anywhere else on your site/app.

Just enclose your SCSS/CSS content some kind of @include v-namespace("prefixNamespaceGoesHere-") { block } mixin stub directive. Any content within that namespaced block scope with ./{some alphabet}/ (ie. a dot and then an alphabet) will be assumed to be a class identifier, and will be prepended with the literal string as specified in the namespace directive.

Example:

#my-home-page {
   .splash-container {
       @include v-namespace('some-custom-prefix-') {
          .listitem {
              background-color:#33141F;
          }
          .col-md-8 {
              display:flex;
          }
          @include v-namespace('another-custom-prefix-') {
              .listitem {
                  background-color:#aabbcc;
              }
          }
          .listitem-k {
             background-color:orange;
          }
       }
   }
}

will become this:

#my-home-page {
   .splash-container {
     
          some-custom-prefix-listitem {
              background-color:#33141F;
          }
          .some-custom-prefix-col-md-8 {
              display:flex;
          }
         
              .another-custom-prefix-listitem {
                  background-color:#aabbcc;
              }
          
          .some-custom-prefix-listitem-k {
             background-color:orange;
          }
       
   }
}

As you can see, namespacing can be nested as well and will be scoped accordingly.

If you are running under SCSS, you can specify a variable name for the component prefix like @include v-namespace($varName). The namespace prefix will be translated as #{$varName} according to SCSS conventions, and will produce something like .#{$varName}className {. If you use variable references, you can manage all custom skinning component namespaces from a central location.

Flags

Custom flags can be enabled within the 2nd parameter of the v-namespace() function.

Eg. v-namespace('the-prefix-', 'mixed').

mixed

Specifies an explicit 'mixed' scope for the v-namespace. When in this mode, you need to prepend all "namespacing" class names with a - prefix in from of the . dot. This allows you to mix both namespaced and global scopes together without having to re-declare an empty string namespace block for global scope.

Example:

@include v-namespace('some-custom-prefix_', 'mixed') {
     .comp {
         .-class-name {
              color:red;
          } 
         .googlemaps {
                background-color:black;
          }
      }
}

becomes

    .some-custom-prefix_comp {
         .some-custom-prefix_class-name {
              color:red;
          } 
         .googlemaps {
                background-color:black;
          }
     }

As you can see, only the .- pattern is replaced by the prefix.

Some Caveats

For simplicity of implementation, the code involves naive find and replace. So it might accidentally replace some strings (particularly within css comments) that might end up being mistaken as CSS class names.

Also, it won't support namespacing any SCSS @include directives or mixins directly within the namespace block and it's only Find+Replace over the current document within namespaced blocks, and doesn't involve an actual AST (Abstract syntax tree) preprocessor that could modify the way the actual file works at compile time itself. However, the advantage is that this will work over any other language besides SCSS/CSS, ie. over plain CSS and even other style syntaxes that would have no issue with the Find+Replace routine.

It's best to leave your CSS code uncommented within namespaced blocks, and/or ensure any . dot character has a leading space after it to avoid accidental find+replace prefixing. eg. Use of content: CSS property would be particular tricky if you need to have an alphabet directly after a preceding dot, and you might have to resort to SCSS variable names declared outside of any component namespaced block to get around the caveat.

Gulp integration

Go to the following URL for gulp integration of this library:

https://github.com/Glidias/gulp-v-namespace/