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

Function parseQuery

packages/core/css-mediaquery/index.ts:121–176  ·  view source on GitHub ↗
(mediaQuery: string)

Source from the content-addressed store, hash-verified

119}
120
121export function parseQuery(mediaQuery: string): MediaQueryExpression[] {
122 const mediaQueryStrings = mediaQuery.split(',');
123
124 return mediaQueryStrings.map((query) => {
125 query = query.trim();
126
127 const captures = query.match(RE_MEDIA_QUERY);
128
129 // Media query must be valid
130 if (!captures) {
131 throw new SyntaxError(`Invalid CSS media query: '${query}'`);
132 }
133
134 const modifier = captures[1];
135 const type = captures[2];
136 const featureString = ((captures[3] || '') + (captures[4] || '')).trim();
137
138 const expression: MediaQueryExpression = {
139 inverse: !!modifier && modifier.toLowerCase() === 'not',
140 type: MediaQueryType[type ? type.toLowerCase() : 'all'] ?? 'all',
141 features: [],
142 };
143
144 // Check for media query features
145 if (!featureString) {
146 return expression;
147 }
148
149 // Split features string into a list
150 const features = featureString.match(/\([^\)]+\)/g);
151
152 // Media query must be valid
153 if (!features) {
154 throw new SyntaxError(`Invalid CSS media query features: '${featureString}' on '${query}'`);
155 }
156
157 for (const feature of features) {
158 const captures = feature.match(RE_MQ_EXPRESSION);
159
160 // Media query must be valid
161 if (!captures) {
162 throw new SyntaxError(`Invalid CSS media query feature: '${feature}' on '${query}'`);
163 }
164
165 const featureData = captures[1].toLowerCase().match(RE_MQ_FEATURE);
166
167 expression.features.push({
168 modifier: featureData[1],
169 property: featureData[2],
170 value: captures[2],
171 });
172 }
173
174 return expression;
175 });
176}

Callers 2

matchQueryFunction · 0.85
index.spec.tsFile · 0.85

Calls 3

mapMethod · 0.65
matchMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected