@alicd/templateparser
Version:
walle template parser
58 lines (48 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _output = require('./output');
var _output2 = _interopRequireDefault(_output);
var _express = require('./express');
var _express2 = _interopRequireDefault(_express);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @license
* Copyright Alibaba Group and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var _transformStr2Hump = function _transformStr2Hump(str) {
var re = /-(\w)/g;
return str.replace(re, function ($0, $1) {
return $1.toUpperCase();
});
};
/**
* handle the style attribute format.
* eg:
* style="color:#F00;width:100px;" => style="{color:'#F00',width:'100px'}"
*/
exports.default = function (styleAttr, runtimeOn) {
if (_express2.default.test(styleAttr)) {
return (0, _output2.default)(styleAttr, runtimeOn);
} else {
if (typeof styleAttr === 'string') {
var styleArr = styleAttr.split(/;/g);
var styleObj = {};
var i = 0;
var j = styleArr.length;
for (; i < j; i += 1) {
if (styleArr[i]) {
var item = styleArr[i].split(':');
var name = _transformStr2Hump(item[0].replace(/\s/g, ''));
item[1] && (styleObj[name] = item[1].trim());
}
}
return styleObj;
}
return {};
}
};