1.0.23 • Published 6 years ago
cssdom v1.0.23
cssdom — Simplified css syntax check or css dom handle
var CssDom = require('cssdom');install
npm install cssdom --savetest
npm testbrowserify
Exports cssdom to front
browserify cssdom.js -s CssDom > cssdom.front.jsonline demo
http://douzi8.github.io/cssdom/
API
CssDom(str)
- {string}
strrequired
var css = new CssDom('a{}');css.dom
The structure of css dom, it's an array with object item, list item type
charset
// @charset 'utf8';
{
type: 'charset',
value: 'utf8'
}import
// @import 'custom.css';
{
type: 'import',
value: "'custom.css'"
}rule
// .a { color: #333;}
{
type: 'rule',
selectors: ['.a'],
declarations: {
color: '#333'
}
}keyframes
// @-webkit-keyframes progress-bar-stripes{}
{
type: 'keyframes',
vendor: '-webkit-',
value: 'progress-bar-stripes',
rules: [
// It's rule type
...
]
}document
{
type: 'document',
vendor: '-moz-',
value: 'url-prefix()',
rules: [
// It's rule type
...
]
}media
// @media print {body { font-size: 10pt }}
{
type: 'media',
value: 'print',
rules: [
// It's rule type
...
]
}supports
// @supports (display: flex) {}
{
type: 'supports',
value: '(display: flex)',
rules: [
// It's rule type
...
]
}comment
// /*1*/
{
type: 'comment',
value: '1'
}css.css(dom, css)
Change css declarations
- {object}
domrequired - {object}
cssrequired
css.css(css.dom[0], {
'color': 'red'
});css.selector(selector, css)
Change css by selector, if css is empty, it will return css dom
- {string}
selectorrequired - {object}
css
css.selector('.cls', {
width: '200px',
height: function(value, dom) {
// value -> origin value
// dom -> current css dom
return value;
},
// delete color key
color: ''
});
css.selector('.cls');css.property(property, css)
Change css by property
- {string}
selectorrequired - {object}
cssrequired
css.property('background', {
background: function(value) {
return value;
}
});
var child = css.property('background');
child.forEach(function(dom) {
css.css(dom, {
background: function(value) {
return value.replce(/url\(('[^']*'|"[^"]*"|[^)]*)\)/, function(src) {
return src;
});
}
});
});css.unshift(dom)
- {object}
domrequired
Insert a new css dom to the top of css code
css.unshift({
type: 'comment',
value: 'banner'
});css.push(dom)
- {object}
domrequired
Push a new css dom
css.push({
type: 'rule',
selectors: ['a'],
declarations: {
color: '#333',
'line-height': '20px'
}
});css.validateDom(dom)
- {object|array}
domrequired
Validate the css dom, it's useful for handle css dom by youself
css.validateDom({});
css.validateDom([{}]);css.stringify()
Uglify css code.
it will remove all comment, if you want to keep some comment, your comments will start with /*!
/*!
* keep this comment
*/css.stringify();css.beautify(options)
Beautify css code
- {object} options
- {string} options.indent = ' '
Code indent - {boolean} options.separateRule = false
Separate rules by new lines, default is a blank line
- {string} options.indent = ' '
1.0.23
6 years ago
1.0.22
7 years ago
1.0.21
8 years ago
1.0.20
10 years ago
1.0.19
10 years ago
1.0.17
11 years ago
1.0.16
11 years ago
1.0.15
11 years ago
1.0.14
11 years ago
1.0.13
11 years ago
1.0.12
11 years ago
1.0.11
11 years ago
1.0.10
11 years ago
1.0.8
11 years ago
1.0.7
11 years ago
1.0.6
11 years ago
1.0.5
11 years ago
1.0.4
11 years ago
1.0.3
11 years ago
1.0.2
11 years ago
1.0.1
11 years ago
1.0.0
11 years ago
