MCPcopy Create free account
hub / github.com/cosscom/coss / parseQuery

Function parseQuery

packages/ui/src/hooks/use-media-query.ts:32–58  ·  view source on GitHub ↗
(
  query: BreakpointQuery | MediaQueryInput | (string & {}),
)

Source from the content-addressed store, hash-verified

30}
31
32function parseQuery(
33 query: BreakpointQuery | MediaQueryInput | (string & {}),
34): string {
35 if (typeof query !== "string") {
36 const parts: string[] = [];
37 if (query.min != null) parts.push(resolveMin(query.min));
38 if (query.max != null) parts.push(resolveMax(query.max));
39 if (query.pointer === "coarse") parts.push("(pointer: coarse)");
40 if (query.pointer === "fine") parts.push("(pointer: fine)");
41 if (parts.length === 0) return "(min-width: 0px)";
42 return parts.join(" and ");
43 }
44
45 if (query.startsWith("(")) return query;
46
47 const parts: string[] = [];
48 for (const segment of query.split(":")) {
49 if (segment.startsWith("max-")) {
50 const bp = segment.slice(4);
51 if (bp in BREAKPOINTS) parts.push(resolveMax(bp as Breakpoint));
52 } else if (segment in BREAKPOINTS) {
53 parts.push(resolveMin(segment as Breakpoint));
54 }
55 }
56
57 return parts.length > 0 ? parts.join(" and ") : query;
58}
59
60function getServerSnapshot(): boolean {
61 return false;

Callers 1

useMediaQueryFunction · 0.70

Calls 2

resolveMinFunction · 0.70
resolveMaxFunction · 0.70

Tested by

no test coverage detected