New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-styled-components

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-styled-components - npm Package Compare versions

Comparing version 4.0.3 to 4.1.0-0

2

package.json
{
"name": "jest-styled-components",
"version": "4.0.3",
"version": "4.1.0-0",
"description": "Jest utilities for Styled Components",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

const css = require('css')
const { getCSS } = require('./utils')
const { getCSS, getHashes } = require('./utils')

@@ -58,15 +58,24 @@ const getClassNames = node => {

const replaceClassNames = (classNames, style, code) => {
let index = 0
return classNames.reduce((acc, className) => {
if (style.indexOf(className) > -1) {
return acc.replace(new RegExp(className, 'g'), `c${index++}`)
}
const replaceClassNames = (classNames, style, result) =>
classNames
.filter(className => style.includes(className))
.reduce(
(acc, className, index) =>
acc.replace(new RegExp(className, 'g'), `c${index++}`),
result
)
return acc.replace(
new RegExp(`(className="[^"]*?)${className}\\s?([^"]*")`, 'g'),
'$1$2'
const replaceHashes = (classNames, hashes, result) =>
classNames
.filter(
className => className.startsWith('sc-') || hashes.includes(className)
)
}, `${style}${style ? '\n\n' : ''}${code}`)
}
.reduce(
(acc, className) =>
acc.replace(
new RegExp(`(className="[^"]*?)${className}\\s?([^"]*")`, 'g'),
'$1$2'
),
result
)

@@ -86,4 +95,9 @@ const styleSheetSerializer = {

const code = print(val)
const hashes = getHashes()
return classNames.length ? replaceClassNames(classNames, style, code) : code
let result = `${style}${style ? '\n\n' : ''}${code}`
result = replaceClassNames(classNames, style, result)
result = replaceHashes(classNames, hashes, result)
return result
},

@@ -90,0 +104,0 @@ }

@@ -5,4 +5,2 @@ const css = require('css')

const STYLE_TAGS_REGEXP = /<style[^>]*>([^<]*)</g
const isOverV2 = () => Boolean(ServerStyleSheet)

@@ -18,33 +16,34 @@

const getStyle = html => {
const getHTML = () =>
isServer()
? new ServerStyleSheet().getStyleTags()
: StyleSheet.default.instance.toHTML()
const extract = regex => {
let style = ''
let matches
while ((matches = STYLE_TAGS_REGEXP.exec(html)) !== null) {
style += matches[1].trim()
while ((matches = regex.exec(getHTML())) !== null) {
style += `${matches[1]} `
}
return style
return style.trim()
}
const getStyle = () => extract(/<style[^>]*>([^<]*)</g)
const getCSS = () => {
let style
const style = isOverV2()
? getStyle()
: StyleSheet.rules().map(rule => rule.cssText).join('\n')
if (isOverV2()) {
if (isServer()) {
style = getStyle(new ServerStyleSheet().getStyleTags())
} else {
style = getStyle(StyleSheet.default.instance.toHTML())
}
} else {
style = StyleSheet.rules().map(rule => rule.cssText).join('\n')
}
return css.parse(style)
}
const getHashes = () => extract(/data-styled-components="([^"]*)"/g)
module.exports = {
resetStyleSheet,
getStyle,
getHashes,
getCSS,
}
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