{"name":"css-selector-parser","version":"2.0.0","description":"Just a CSS selector parser.","keywords":["css","css selector","css selector parser"],"author":{"name":"Marat Dulin","email":"mdevils@yandex.ru"},"devDependencies":{"@types/colors":"^1.2.1","@types/jest":"^29.5.2","@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","colors":"*","eslint":"^7.16.0","eslint-config-prettier":"^7.1.0","eslint-plugin-import":"^2.22.1","eslint-plugin-prettier":"^3.3.0","jest":"^29.5.0","prettier":"^2.2.1","ts-jest":"^29.1.0","ts-node":"^8.8.2","typedoc":"^0.24.8","typedoc-plugin-markdown":"^3.15.3","typescript":"^4.1.3"},"repository":{"type":"git","url":"git+https://github.com/mdevils/css-selector-parser.git"},"main":"./lib/index.js","typings":"./lib/index","types":"./lib/index","license":"MIT","scripts":{"build":"tsc","build:docs":"rm -Rf docs && typedoc --excludeInternal --excludeExternals --disableSources --plugin typedoc-plugin-markdown --readme tools/README.md --entryDocument ../README.md --out docs src/index.ts && ts-node tools/cleanup-docs.ts","test":"jest test","test:lib":"TEST_LIB=1 npm run test","lint":"eslint src/**.ts","lint:fix":"eslint --fix src/**.ts","benchmark":"ts-node benchmark/benchmark.ts","prepublishOnly":"npm run build"},"gitHead":"0e517dc411b050964f2a291dcbe2218df9f1ef28","bugs":{"url":"https://github.com/mdevils/css-selector-parser/issues"},"homepage":"https://github.com/mdevils/css-selector-parser#readme","_id":"css-selector-parser@2.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-wzVH7DEojhSSSgBRPrGSs8FIQ7VV9gkBp6cOwhizs5sUsk7Ts0FXc30ej3iez40ddHaCh5nkcdfIMycOVgEibQ==","shasum":"706f3da56b7d24f1022f6862265f2e2947051af6","tarball":"http://registry-npm.ywwl.com/css-selector-parser/download/css-selector-parser-2.0.0.tgz","fileCount":19,"unpackedSize":76622,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWPGEhvoMGEj4ZC74Q0JoDNKo3qBbtNg2UNUlNTnhT+QIgacoZI3iZRB0W9LgI7LrEgspd4Ojm1iEUa7bO7VeaFOE="}],"size":16160,"noattachment":false,"key":"/css-selector-parser/-/css-selector-parser-2.0.0.tgz"},"_npmUser":{"name":"mdevils","email":"mdevils@yandex.ru"},"directories":{},"maintainers":[{"name":"mdevils","email":"mdevils@yandex.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/css-selector-parser_2.0.0_1686598043739_0.11614743649379489"},"_hasShrinkwrap":false,"deprecated":"this package version has been deprecated","readme":"css-selector-parser\n===================\n\n* Fast and low memory CSS selector parser.\n* Parses CSS selector into object-model (AST).\n* Compliant with all historical and modern CSS specs.\n* Covered with tests.\n* Documented.\n* Supported CSS selector standards:\n    * `css1`: https://www.w3.org/TR/CSS1/\n    * `css2`: https://www.w3.org/TR/CSS2/\n    * `css3`/`selectors-3`: https://www.w3.org/TR/selectors-3/\n    * `selectors-4`: https://www.w3.org/TR/selectors-4/\n    * `latest`: refers to `selectors-4`\n    * `progressive`: `latest` + accepts unknown psudo-classes, psudo-elements and attribute case sensitivity modifiers\n\n**Important:**\n * [Migrating from 1.x to 3.x](CHANGELOG.md#migrating-from-1x-to-3x).\n * [Migrating from 2.x to 3.x](CHANGELOG.md#migrating-from-2x-to-3x).\n * [Migrating from 1.x to 2.x](CHANGELOG.md#220).\n\nLatest releases: [Changelog](CHANGELOG.md).\n\nInstallation\n------------\n\n```\nnpm install css-selector-parser\n```\n\nUsage\n-----\n\n### Parsing\n\n```javascript\nimport {createParser} from 'css-selector-parser';\n\nconst parse = createParser();\nconst selector = parse('a[href^=\"/\"], .container:has(nav) > a[href]:nth-child(2)::before');\n\nconsole.log(selector);\n```\n\nProduces:\n\n```javascript\n({\n    type: 'Selector',\n    rules: [\n        {\n            type: 'Rule',\n            items: [\n                { type: 'TagName', name: 'a' },\n                {\n                    type: 'Attribute',\n                    name: 'href',\n                    operator: '^=',\n                    value: { type: 'String', value: '/' }\n                }\n            ]\n        },\n        {\n            type: 'Rule',\n            items: [\n                { type: 'ClassName', name: 'container' },\n                {\n                    type: 'PseudoClass',\n                    name: 'has',\n                    argument: {\n                        type: 'Selector',\n                        rules: [\n                            {\n                                type: 'Rule',\n                                items: [ { type: 'TagName', name: 'nav' } ]\n                            }\n                        ]\n                    }\n                }\n            ],\n            nestedRule: {\n                type: 'Rule',\n                items: [\n                    { type: 'TagName', name: 'a' },\n                    { type: 'Attribute', name: 'href' },\n                    {\n                        type: 'PseudoClass',\n                        name: 'nth-child',\n                        argument: { type: 'Formula', a: 0, b: 2 }\n                    },\n                    {\n                        type: 'PseudoElement',\n                        name: 'before'\n                    }\n                ],\n                combinator: '>'\n            }\n        }\n    ]\n})\n```\n\n### Constructing AST and rendering\n\n```javascript\nimport {ast, render} from 'css-selector-parser';\n\nconst selector = ast.selector({\n    rules: [\n        ast.rule({\n            items: [\n                ast.tagName({name: 'a'}),\n                ast.attribute({name: 'href', operator: '^=', value: ast.string({value: '/'})})\n            ]\n        }),\n        ast.rule({\n            items: [\n                ast.className({name: 'container'}),\n                ast.pseudoClass({\n                    name: 'has',\n                    argument: ast.selector({\n                        rules: [ast.rule({items: [ast.tagName({name: 'nav'})]})]\n                    })\n                })\n            ],\n            nestedRule: ast.rule({\n                combinator: '>',\n                items: [\n                    ast.tagName({name: 'a'}),\n                    ast.attribute({name: 'href'}),\n                    ast.pseudoClass({\n                        name: 'nth-child',\n                        argument: ast.formula({a: 0, b: 2})\n                    }),\n                    ast.pseudoElement({name: 'before'})\n                ]\n            })\n        })\n    ]\n});\n\nconsole.log(render(selector)); // a[href^=\"/\"], .container:has(nav) > a[href]:nth-child(2)::before\n```\n\nAPI\n---\n\n* [Full API Documentation](docs/modules.md)\n* [Parsing CSS selectors](docs/modules.md#createParser)\n* [Constructing CSS AST](docs/modules.md#ast)\n* [Rendering CSS AST](docs/modules.md#render)\n\nLICENSE\n-------\n\nMIT\n\n## Security contact information\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure.\n","publish_time":1686598043988,"_cnpm_publish_time":1686598043988,"dist-tags":{"latest":"3.3.0"}}