Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Modular CSS bundler for browserify. Works with npm modules like browserify does.
Given some inline CSS:
const css = require('sheetify')
const html = require('bel')
const prefix = css`
:host > h1 {
text-align: center;
}
`
const tree = html`
<section class=${prefix}>
<h1>My beautiful, centered title</h1>
</section>
`
document.body.appendChild(tree)
Compile with browserify using -t sheetify
:
$ browserify -t sheetify index.js > bundle.js
CSS classes are namespaced based on the content hash:
._60ed23ec9f > h1 {
text-align: center;
}
And the rendered HTML includes the namespace:
<section class="_60ed23ec9f">
<h1>My beautiful, centered title</h1>
</section>
The element that gets a prefix applied can be styled using the :host
pseudoselector:
const css = require('sheetify')
const html = require('bel')
const prefix = css`
:host {
background-color: blue;
}
:host > h1 {
text-decoration: underline;
}
`
const tree = html`
<section class=${prefix}>
<h1>My beautiful, centered title</h1>
</section>
`
document.body.appendChild(tree)
By using :host
we are able to provide styles for the parent element:
._60ed23ec9f {
background-color: blue;
}
._60ed23ec9f > h1 {
text-decoration: underline;
}
<section class="_60ed23ec9f">
<h1>My beautiful, centered title</h1>
</style>
Sheetify is very good for namespacing static css assets in your javaScript code. Currently there is no support for dynamic variables within sheetify, however you could achieve this by setting the inline style property of an element.
const css = require('sheetify')
const html = require('bel')
const sectionWidth = '100px';
const prefix = css`
:host {
background-color: blue;
}
:host > h1 {
text-decoration: underline;
}
`
const tree = html`
<section class=${prefix} style="width:${sectionWidth}">
<h1>My beautiful, centered title</h1>
</section>
`
document.body.appendChild(tree)
Should you want to, you could even set dynamic variables in an object and do a rather complicated JSON.stringify with a replace on that object to turn it into a style for an element.
const dynamicStyles = {
width: global.window.innerWidth,
height: global.window.innerHeight,
}
let dynamicStyleString = JSON.stringify(dynamicStyles)
.replace(/\,/g,';')
.replace(/\"/g,'')
.replace(/\{|\}/g,'')
const tree = html`
<div style="${dynamicStyleString}">
<h1>My beautiful, window width</h1>
</div>
`
To include an external CSS file you can pass a path to sheetify as
sheetify('./my-file.css')
:
const css = require('sheetify')
const html = require('bel')
const prefix = css('./my-styles.css')
const tree = html`
<section class=${prefix}>
<h1>My beautiful, centered title</h1>
</section>
`
document.body.appendChild(tree)
To consume a package from npm that has .css
file in its main
or style
field:
const css = require('sheetify')
css('normalize.css')
Packages from npm will not be namespaced by default.
To write the compiled CSS to a separate file, rather than keep it in the bundle use css-extract:
$ browserify index.js \
-t [ sheetify ] \
-p [ css-extract -o bundle.css ] index.js \
-o bundle.js
css-extract can also write to a stream from the JS api, look at the documentation to see how.
Sheetify uses transforms that take CSS and apply a transform. For example include sheetify-cssnext to support autoprefixing, variables and more:
const css = require('sheetify')
const html = require('bel')
const prefix = css`
h1 {
transform: translate(0, 0);
}
`
const tree = html`
<section class=${prefix}>
<h1>My beautiful, centered title</h1>
</section>
`
document.body.appendChild(tree)
Compile with browserify using -t [ sheetify -t sheetify-cssnext ]
:
$ browserify -t [ sheetify -t sheetify-cssnext ] index.js > bundle.js
Transforms the CSS into:
h1 {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
Browserify transforms accept either flags from the command line using subargs:
$ browserify -t [ sheetify -t sheetify-cssnext ] index.js > bundle.js
Or the equivalent options by passing in a configuration object in the JavaScript API:
const browserify = require('browserify')
const b = browserify(path.join(__dirname, 'transform/source.js'))
b.transform('sheetify', { transform: [ 'sheetify-cssnext' ] })
b.bundle().pipe(process.stdout)
The following options are available:
Options:
-t, --transform Consume a sheetify transform
$ npm install sheetify
FAQs
Modular CSS bundler
The npm package sheetify receives a total of 73 weekly downloads. As such, sheetify popularity was classified as not popular.
We found that sheetify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.