UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.43 kB
{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["import { getWindow } from \"ssr-window\";\r\n\r\nexport type TIsMediaQueryArgs = Parameters<typeof isMediaQuery>;\r\n\r\nexport type TIsMediaQueryReturn = ReturnType<typeof isMediaQuery>;\r\n\r\n/**\r\n * Gets a result of testing of a CSS media query\r\n * @param str{String} source media query string\r\n * @returns {boolean}\r\n * @throws {TypeError} isMediaQuery: str must be a string\r\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Testing_media_queries\r\n * @example\r\n * // How to check if a user device has portrait or landscape orientation?\r\n * const mediaQuery = \"(orientation: portrait)\";\r\n * const isPortrait = isMediaQuery(mediaQuery);\r\n * console.log(isPortrait); // => false\r\n */\r\nexport const isMediaQuery = (str: string): boolean => {\r\n if (typeof str !== \"string\") {\r\n throw new TypeError(\"isMediaQuery: str must be a string\");\r\n }\r\n\r\n const query = str.startsWith(\"(\") && str.endsWith(\")\") ? str : `(${str})`;\r\n\r\n return getWindow().matchMedia(query)?.matches ?? false;\r\n};\r\n"],"names":["isMediaQuery","str","TypeError","query","startsWith","endsWith","getWindow","matchMedia","matches"],"mappings":";;;;;;;;;;;;GAkBO,MAAMA,aAAgBC,MAC3B,UAAWA,MAAQ,SACjB,MAAM,IAAIC,UAAU,sCAGtB,MAAMC,MAAQF,IAAIG,WAAW,MAAQH,IAAII,SAAS,KAAOJ,IAAM,IAAIA,OAEnE,OAAOK,YAAYC,WAAWJ,QAAQK,SAAW"}