Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
CSS in ES6
npm install -g cassis
import Cassis from 'cassis';
const css = new Cassis({
body : { color : '#888' },
p : { margin : '10px', padding : 0 }
});
console.log(css.render());
body {
color: #888;
}
p {
margin: 10px;
padding: 0;
}
For dev purposes, the Style
class allows live styling into a dynamic <style/>
element.
import Cassis from 'cassis';
const { style } = Cassis;
const body = new Cassis({ body : { color : '#888' } });
// Add rule to style
style.add(body);
// check if style has selector
style.has('body'); // true
You can call the Eric Meyer Reset 2.0 which ships by default with Cassis:
import Cassis from 'cassis';
import Reset from 'cassis/dist/lib/reset';
style.add(new Reset());
You can find a demo of Cassis in the file index.html. Just open it with your favorite browser.
You can add rules also by using the add
method
import Cassis from 'cassis';
const css = new Cassis({
body : { color : '#888' }
});
css.addRule({
p : { margin : '10px', padding : 0 }
});
console.log(css.render());
body {
color: #888;
}
p {
margin: 10px;
padding: 0;
}
Declarations can be re-used such as:
import Cassis from 'cassis';
const { Declaration } = Cassis;
const border = new Declaration({ 'border' : '1px solid black' });
const css = new Cassis({ h1 : { border }, p : { border } });
console.log(css.render());
h1 {
border: 1px solid black;
}
p {
border: 1px solid black;
}
You can have nested rules such as:
import Cassis from 'cassis';
const css = new Cassis({
'p' : {
'.foo' : {
color : 'red'
},
'.bar' : {
color : 'blue'
}
}
});
console.log(css.render());
p .foo {
color: red;
}
p .bar {
color: blue;
}
On a side note, we discourage you to use too deep nested rules. Remember that CSS read from right to left (children to parents) and deep nested selectors are slow to be processed.
You can use &
in rules to attach it to rules such as :
import Cassis from 'cassis';
const css = new Cassis({
'p' : {
'&.foo' : {
color : 'red'
}
}
});
console.log(css.render());
p.foo {
color: red;
}
Since in JavaScript object cannot have properties with the same name but CSS can, this is how to do it:
import Cassis from 'cassis';
const css = new Cassis({
'.row' : {
'display': ['-webkit-flex', 'flex']
}
});
console.log(css.render());
.row {
display: -webkit-flex;
display: flex;
}
import Cassis from 'cassis';
const css = new Cassis({
'input' : {
'color' : 'red',
'placeholder' : Cassis.Util.placeholder('input', { color : 'orange' })
}
});
console.log(css.render());
input {
color: red;
}
input::-webkit-input-placeholder {
color: orange;
}
input:-moz-placeholder {
color: orange;
}
input::-moz-placeholder {
color: orange;
}
input:-ms-input-placeholder {
color: orange;
}
FAQs
CSS in JavaScript
The npm package cassis receives a total of 0 weekly downloads. As such, cassis popularity was classified as not popular.
We found that cassis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.