From ac508985196c76850babf336f9d0646688c51935 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Sun, 20 Jun 2021 20:45:15 +0800 Subject: [PATCH] feat(wxs): style.wxs support camel case attr (#4281) --- packages/wxs/style.wxs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/wxs/style.wxs b/packages/wxs/style.wxs index c39c810f..d88ca7c9 100644 --- a/packages/wxs/style.wxs +++ b/packages/wxs/style.wxs @@ -2,6 +2,16 @@ var object = require('./object.wxs'); var array = require('./array.wxs'); +function kebabCase(word) { + var newWord = word + .replace(getRegExp("[A-Z]", 'g'), function (i) { + return '-' + i; + }) + .toLowerCase() + + return newWord; +} + function style(styles) { if (array.isArray(styles)) { return styles @@ -21,7 +31,7 @@ function style(styles) { return styles[key] != null && styles[key] !== ''; }) .map(function (key) { - return [key, [styles[key]]].join(':'); + return [kebabCase(key), [styles[key]]].join(':'); }) .join(';'); }