UNPKG

@web3r/flowerkit

Version:

A collection of more than 60 often used utility JS functions that simplify frontend development.

14 lines (13 loc) 619 B
import ow from"ow";import{getDocument}from"ssr-window"; /** * Checks if string is valid CSS selector * @param str{String} - source selector * @return {boolean} * @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors * @example * // How to check if CSS selector is valid? * const selector = "#myElement"; * const isValid = isSelectorValid(selector); * console.log(isValid); // => true */const isSelectorValid=str=>{ow(str,ow.string.not.empty);try{getDocument().createDocumentFragment().querySelector(str)}catch{return false}return true};export{isSelectorValid}; //# sourceMappingURL=index.js.map