{"id":25141,"library":"css-select-umd","title":"css-select","description":"A CSS selector compiler/engine that turns CSS selectors into functions for testing and querying DOM elements. Current stable version is 2.x (v1.3.0-rc0 is a pre-release of a UMD build). It uses right-to-left execution for efficient O(n) performance, unlike left-to-right engines like Sizzle. Features full CSS3 selectors, partial jQuery extensions, and uses domhandler/domutils as default DOM adapter. Released regularly via npm; TypeScript types included since v1.3.0. Key differentiator: performance through right-to-left compilation and a function-stack approach.","status":"active","version":"1.3.0-rc0","language":"javascript","source_language":"en","source_url":"git://github.com/matt-gadd/css-select","tags":["javascript","css","selector","sizzle","typescript"],"install":[{"cmd":"npm install css-select-umd","lang":"bash","label":"npm"},{"cmd":"yarn add css-select-umd","lang":"bash","label":"yarn"},{"cmd":"pnpm add css-select-umd","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for default DOM structure used by css-select","package":"domhandler","optional":false},{"reason":"Default adapter for DOM operations","package":"domutils","optional":false},{"reason":"CSS selector parser used internally","package":"css-what","optional":false}],"imports":[{"note":"ESM default import; for CommonJS use require('css-select-umd') but the UMD build also supports global scope.","wrong":"const CSSselect = require('css-select-umd')","symbol":"CSSselect","correct":"import CSSselect from 'css-select-umd'"},{"note":"selectOne is a named export; do not access as a method of default import.","wrong":"import CSSselect from 'css-select-umd'; CSSselect.selectOne(...)","symbol":"selectOne","correct":"import { selectOne } from 'css-select-umd'"},{"note":"compile is a named export; available as a side-effect of importing the package.","wrong":"const compile = require('css-select').compile","symbol":"compile","correct":"import { compile } from 'css-select-umd'"}],"quickstart":{"code":"import CSSselect from 'css-select-umd';\nimport { DomHandler } from 'domhandler';\nimport { parseDocument } from 'htmlparser2';\n\nconst html = '<div><p class=\"foo\">Hello</p><p class=\"bar\">World</p></div>';\nconst handler = new DomHandler((err, dom) => {\n  if (err) throw err;\n  const elements = CSSselect('p.foo', dom);\n  console.log(elements.length); // 1\n  console.log(elements[0].children[0].data); // 'Hello'\n});\nparseDocument(html, handler);","lang":"typescript","description":"Shows how to import and use css-select-umd to query DOM elements from parsed HTML using htmlparser2."},"warnings":[{"fix":"Use stable version 2.x instead or pin to exact pre-release version.","message":"Version 1.3.0-rc0 is a pre-release of a UMD build; API may change before stable release.","severity":"breaking","affected_versions":"1.3.0-rc0"},{"fix":"Import from 'css-select-umd' or from 'css-select' if not using UMD.","message":"The package name is 'css-select-umd' but exports are identical to 'css-select' UMD build; ensure you use correct import path.","severity":"gotcha","affected_versions":">=1.3.0-rc0"},{"fix":"Upgrade to css-select v2+ for latest API and use 'css-select' package directly instead of UMD bundle if possible.","message":"Older versions (<2.0) of the underlying 'css-select' used a different API; 'css-select-umd' is based on v1 branch and may not have newer features.","severity":"deprecated","affected_versions":"<1.3.0"},{"fix":"Wrap selector calls in try-catch or validate selectors before passing to CSSselect.","message":"CSSselect throws errors on invalid selectors; this differs from jQuery which silently ignores them.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'import CSSselect from 'css-select-umd'' or 'const CSSselect = require('css-select-umd').default'","cause":"Using CommonJS require on an ESModule default export without proper interop.","error":"TypeError: CSSselect is not a function"},{"fix":"Install domhandler: npm install domhandler","cause":"Missing peer dependency domhandler which is required for default DOM structure.","error":"Cannot find module 'domhandler'"},{"fix":"Ensure you pass a valid DOM tree (e.g., from domhandler) and that elements have a 'type' property.","cause":"Passing a non-DOM element or invalid DOM node to CSSselect.","error":"TypeError: Cannot read properties of undefined (reading 'type')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}