Weex <style>
Transformer
Features
- convert a
<style>
element to JSON format - autofix common mistakes
- friendly warnings
API
parse(code, done)
validate(json, done)
validateItem(name, value)
util api
util.hyphenedToCamelCase(value)
util.camelCaseToHyphened(value)
function parse(code, done) {}
function validate(json, done) {}
function done(err, data) {}
function validateItem(name, value) {}
Validation
- rule check: only common rule type supported, othres will be ignored
- selector check: only single-classname selector is supported, others will be ignored
- prop name check: out-of-defined prop name will be warned but preserved
- prop value check: common prop value mistakes will be autofixed or ignored
- color type: keywords,
#xxx
-> warning: #xxxxxx
- color type:
transparent
-> error: not supported - length type:
100px
-> warning: 100
Demo
var styler = require('weex-styler')
var code = 'html {color: #000000;} .foo {color: red; -webkit-transform: rotate(90deg); width: 200px;}'
styler.parse(code, function (err, data) {
err
data.jsonStyle
data.log[]
})
var jsonStyle = {
foo: {
color: 'red',
webkitTransform: 'rotate(90deg)',
width: '200px'
}
}
styler.validate(json, function (err, data) {
err
data.jsonStyle
data.log[]
})