UNPKG

@ohu-mobile/core

Version:
40 lines (39 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.filterEmpty = filterEmpty; exports.isEmptyElement = isEmptyElement; exports.parseStyleText = void 0; var camelizeRE = /-(\w)/g; var camelize = function camelize(str) { return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; }); }; var parseStyleText = exports.parseStyleText = function parseStyleText() { var cssText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var camel = arguments.length > 1 ? arguments[1] : undefined; var res = {}; var listDelimiter = /;(?![^(]*\))/g; var propertyDelimiter = /:(.+)/; cssText.split(listDelimiter).forEach(function (item) { if (item) { var tmp = item.split(propertyDelimiter); if (tmp.length > 1) { var k = camel ? camelize(tmp[0].trim()) : tmp[0].trim(); res[k] = tmp[1].trim(); } } }); return res; }; function isEmptyElement(c) { return !(c.tag || c.text && c.text.trim() !== ''); } function filterEmpty() { var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; return children.filter(function (c) { return !isEmptyElement(c); }); }