Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-scopify

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-scopify - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

.tern-project

81

index.js
'use strict';
var postcss = require('postcss');
var conditionalGroupRules = ['media','supports','document'];
module.exports = postcss.plugin('postcss-scopify', scopify);
function scopify(scope, options) {
options = options || {};
return function(root) {
options = options || {};
// guard statment- allow only valid scopes
if(!isValidScope(scope)){
throw root.error('invalid scope', { plugin: 'postcss-scopify' });
}
root.walkRules(function (rule) {
if (!rule.selectors){
return rule;
}
return function(root) {
if(rule.parent.type === 'atrule' && (rule.parent.name === '-webkit-keyframes' || rule.parent.name === 'keyframes')){
return rule;
};
rule.selectors = rule.selectors.map(function(selector) {
if (isScopeApplied(selector,scope)) {
return selector;
// guard statment- allow only valid scopes
if(!isValidScope(scope)){
throw root.error('invalid scope', { plugin: 'postcss-scopify' });
}
return scope + ' ' + selector;
root.walkRules(function (rule) {
});
});
};
// skip scoping of special rules (certain At-rules, nested, etc')
if(!isRuleScopable(rule)){
return rule;
}
rule.selectors = rule.selectors.map(function(selector) {
if (isScopeApplied(selector,scope)) {
return selector;
}
// special case for a top level '&' selector, resolves to scope
if (selector === '&') {
return scope;
}
return scope + ' ' + selector;
});
});
};
}

@@ -45,4 +50,4 @@

function isScopeApplied(selector,scope) {
var selectorTopScope = selector.split(" ",1)[0];
return selectorTopScope === scope;
var selectorTopScope = selector.split(" ",1)[0];
return selectorTopScope === scope;
}

@@ -64,1 +69,27 @@

}
/**
* Determine if rule should be scoped
*
* @param {rule} rule
*/
function isRuleScopable(rule){
if (!rule.selectors){
return false;
}
else if(rule.parent.type !== 'root') {
if (rule.parent.type === 'atrule' && conditionalGroupRules.indexOf(rule.parent.name) > -1){
return true;
}
else {
return false;
}
}
else {
return true;
}
}
{
"name": "postcss-scopify",
"version": "0.1.7",
"version": "0.1.8",
"description": "PostCSS plugin that adds a user input scope to each selector",

@@ -5,0 +5,0 @@ "keywords": [

@@ -27,2 +27,6 @@ # PostCSS Scopify [![Build Status][ci-img]][ci]

}
& {
/* declarations */
}
```

@@ -35,2 +39,6 @@ __Example output__

}
#scope {
/* declarations */
}
```

@@ -64,2 +72,5 @@

## Change Log
### v0.1.8
closes [#10](https://github.com/pazams/postcss-scopify/issues/10)
### v0.1.7

@@ -66,0 +77,0 @@ fixes [#7](https://github.com/pazams/postcss-scopify/issues/7)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc