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

babel-plugin-cssta-stylename

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

babel-plugin-cssta-stylename - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

2

package.json
{
"name": "babel-plugin-cssta-stylename",
"version": "0.1.5",
"version": "0.1.6",
"description": "Transform css imports into cssta template components",

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

@@ -24,30 +24,39 @@ const fs = require('fs')

const regex = new RegExp(`\\.${className}(?:[^\\w\\-]|$)`)
const newAst = {
let keyframes = []
const newAst = getNewAst(ast.stylesheet.rules.map(rule => {
if (rule.type === 'keyframes') {
keyframes.push(rule)
} else {
return matchRule(rule, regex)
}
}).filter(Boolean))
let matchingCss = css.stringify(newAst) || ''
keyframes = keyframes.filter(({ name }) => (
name && new RegExp('[:,\\s]' + name + '[:,\\s]').test(matchingCss)
))
if (keyframes.length > 0) {
matchingCss += (matchingCss ? '\n' : '') + css.stringify(getNewAst(keyframes))
}
return matchingCss
}
function getNewAst (rules) {
return {
type: 'stylesheet',
stylesheet: {
rules: []
rules: rules
}
}
newAst.stylesheet.rules = ast.stylesheet.rules.map(rule => {
if (rule.type === 'media') {
const rules = rule.rules.map(rule => {
if (rule.type === 'rule') {
const selectors = rule.selectors.map(selector => {
if (regex.test(selector)) return selector
}).filter(Boolean)
if (selectors.length > 0) return { ...rule, selectors }
}
}).filter(Boolean)
if (rules.length > 0) return { ...rule, rules }
} else if (rule.type === 'keyframes') {
return rule
} else if (rule.type === 'rule') {
const selectors = rule.selectors.map(selector => {
if (regex.test(selector)) return selector
}).filter(Boolean)
if (selectors.length > 0) return { ...rule, selectors }
}
}).filter(Boolean)
}
return css.stringify(newAst)
function matchRule (rule, regex) {
if (rule.rules) {
const rules = rule.rules.map(rule => matchRule(rule, regex)).filter(Boolean)
if (rules.length > 0) return { ...rule, rules }
} else if (rule.selectors) {
const selectors = rule.selectors.filter(selector => regex.test(selector))
if (selectors.length > 0) return { ...rule, selectors }
}
}

@@ -54,0 +63,0 @@

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