MCPcopy
hub / github.com/baidu/amis / formatStyleObject

Function formatStyleObject

packages/amis/__tests__/renderers/PopOver.test.tsx:28–49  ·  view source on GitHub ↗
(style: string | null, px2number = true)

Source from the content-addressed store, hash-verified

26});
27
28function formatStyleObject(style: string | null, px2number = true) {
29 if (!style) {
30 return {};
31 }
32
33 // 去除注释 /* xx */
34 style = style.replace(/\/\*[^(\*\/)]*\*\//g, '');
35
36 const res: any = {};
37 style.split(';').forEach((item: string) => {
38 if (!item || !String(item).includes(':')) return;
39
40 const [key, value] = item.split(':');
41
42 res[String(key).trim()] =
43 px2number && value.endsWith('px')
44 ? Number(String(value).replace(/px$/, ''))
45 : String(value).trim();
46 });
47
48 return res;
49}
50
51test('Renderer:PopOver in table', async () => {
52 const {container, rerender, getByText} = render(

Callers 1

PopOver.test.tsxFile · 0.70

Calls 2

replaceMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected