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

postcss-prefix

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-prefix - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

58

index.js
const postcss = require('postcss')
const Selector = require('postcss-selector-parser')

@@ -10,9 +11,56 @@ module.exports = postcss.plugin('postcss-prefix', postcssPrefix)

root.walkRules(function (rule) {
rule.selectors = rule.selectors.map(function (selector) {
if (rule.selector.indexOf(':root') === 0) return selector
return prefix + selector
})
rule.selector = rule.selectors.join(', ')
const selector = Selector(
transformSelectors
).process(rule.selector).result
rule.selector = selector
})
}
function transformSelectors (selectors) {
selectors.eachInside(function (selector) {
if (
// if parent is not selector and
selector.parent.type !== 'selector' ||
// if not first node in container
selector.parent.nodes[0] !== selector
) return
const prefixNode = getPrefixNode(prefix)
if (selector.type === 'pseudo') {
switch (selector.value) {
case ':root':
return
case ':host':
const replacement = Selector.selector()
replacement.nodes = [prefixNode].concat(selector.clone().nodes)
selector.replaceWith(replacement)
return
}
}
// prefix
//
// start by prepending a space combinator
selector.parent.prepend(Selector.combinator({ value: ' ' }))
// then prepend the prefix node, preserving spacing
prefixNode.spaces.before = selector.spaces.before
selector.spaces.before = ''
selector.parent.prepend(prefixNode)
})
}
}
function getPrefixNode (prefix) {
const sigil = prefix[0]
const value = prefix.slice(1)
switch (sigil) {
case '#':
return Selector.id({ value })
case '.':
return Selector.className({ value })
}
}

5

package.json
{
"name": "postcss-prefix",
"version": "1.0.1",
"version": "1.0.2",
"dependencies": {
"postcss": "^5.0.8"
"postcss": "^5.0.8",
"postcss-selector-parser": "^1.3.0"
},

@@ -7,0 +8,0 @@ "devDependencies": {

@@ -11,3 +11,3 @@ const prefix = require('../')

const out = postcss()
.use(prefix('#hello-world '))
.use(prefix('#hello-world'))
.process(css)

@@ -14,0 +14,0 @@ .toString()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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