MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / parseCSSShorthand

Function parseCSSShorthand

packages/core/ui/styling/css-utils.ts:50–88  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

48}
49
50export function parseCSSShorthand(value: string): {
51 values: Array<CoreTypes.LengthType>;
52 color: string;
53 inset: boolean;
54} {
55 const parts = value.trim().split(WHITE_SPACE_RE);
56 const first = parts[0];
57
58 if (['', 'none', 'unset'].includes(first)) {
59 return null;
60 }
61
62 const invalidColors = ['inset', 'unset'];
63 const inset = parts.includes('inset');
64 const last = parts[parts.length - 1];
65 let color = 'black';
66 if (first && !isLength(first) && !invalidColors.includes(first)) {
67 color = first;
68 } else if (last && !isLength(last) && !invalidColors.includes(last)) {
69 color = last;
70 }
71
72 const values = parts
73 .filter((n) => !invalidColors.includes(n))
74 .filter((n) => n !== color)
75 .map((val) => {
76 try {
77 return Length.parse(val);
78 } catch (err) {
79 return CoreTypes.zeroLength;
80 }
81 });
82
83 return {
84 inset,
85 color,
86 values,
87 };
88}

Callers 2

parseCSSShadowFunction · 0.90
parseCSSStrokeFunction · 0.90

Calls 5

isLengthFunction · 0.85
includesMethod · 0.80
mapMethod · 0.65
parseMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected