{"name":"@csstools/css-parser-algorithms","description":"Algorithms to help you parse CSS from an array of tokens.","version":"2.7.1","contributors":[{"name":"Antonio Laguna","email":"antonio@laguna.es","url":"https://antonio.laguna.es"},{"name":"Romain Menke","email":"romainmenke@gmail.com"}],"license":"MIT","funding":[{"type":"github","url":"https://github.com/sponsors/csstools"},{"type":"opencollective","url":"https://opencollective.com/csstools"}],"engines":{"node":"^14 || ^16 || >=18"},"type":"module","main":"dist/index.cjs","module":"dist/index.mjs","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"default":"./dist/index.cjs"}}},"peerDependencies":{"@csstools/css-tokenizer":"^2.4.1"},"scripts":{},"homepage":"https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms#readme","repository":{"type":"git","url":"git+https://github.com/csstools/postcss-plugins.git","directory":"packages/css-parser-algorithms"},"bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"keywords":["css","parser"],"_id":"@csstools/css-parser-algorithms@2.7.1","gitHead":"2686e10cf800941fa9f9de7cb1c379997478362c","types":"./dist/index.d.ts","_nodeVersion":"22.1.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-2SJS42gxmACHgikc1WGesXLIT8d/q2l0UFM7TaEeIzdFCE/FPMtTiizcPGGJtlPo2xuQzY09OhrLTzRxqJqwGw==","shasum":"6d93a8f7d8aeb7cd9ed0868f946e46f021b6aa70","tarball":"http://registry-npm.ywwl.com/@csstools/css-parser-algorithms/download/@csstools/css-parser-algorithms-2.7.1.tgz","fileCount":7,"unpackedSize":45834,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDoim05B3S2zUR0mDY+Tkz3XAJLAlPh2iFzG89unRVdYgIhANKccrLCfZkUGyl8kiEQoGp4XAcWcGP4retNNknO1AvA"}],"size":10042,"noattachment":false,"key":"/@csstools/css-parser-algorithms/-/@csstools/css-parser-algorithms-2.7.1.tgz"},"_npmUser":{"name":"romainmenke","email":"romainmenke@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/css-parser-algorithms_2.7.1_1720258455699_0.980842572280759"},"_hasShrinkwrap":false,"readme":"# CSS Parser Algorithms\n\n[<img alt=\"npm version\" src=\"https://img.shields.io/npm/v/@csstools/css-parser-algorithms.svg\" height=\"20\">][npm-url]\n[<img alt=\"Build Status\" src=\"https://github.com/csstools/postcss-plugins/workflows/test/badge.svg\" height=\"20\">][cli-url]\n[<img alt=\"Discord\" src=\"https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white\">][discord]\n\nImplemented from : https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/\n\n## API\n\n[Read the API docs](./docs/css-parser-algorithms.md)\n\n## Usage\n\nAdd [CSS Parser Algorithms] to your project:\n\n```bash\nnpm install @csstools/css-parser-algorithms @csstools/css-tokenizer --save-dev\n```\n\n[CSS Parser Algorithms] only accepts tokenized CSS.\nIt must be used together with `@csstools/css-tokenizer`.\n\n\n```js\nimport { tokenizer, TokenType } from '@csstools/css-tokenizer';\nimport { parseComponentValue } from '@csstools/css-parser-algorithms';\n\nconst myCSS =  `@media only screen and (min-width: 768rem) {\n\t.foo {\n\t\tcontent: 'Some content!' !important;\n\t}\n}\n`;\n\nconst t = tokenizer({\n\tcss: myCSS,\n});\n\nconst tokens = [];\n\n{\n\twhile (!t.endOfFile()) {\n\t\ttokens.push(t.nextToken());\n\t}\n\n\ttokens.push(t.nextToken()); // EOF-token\n}\n\nconst options = {\n\tonParseError: ((err) => {\n\t\tthrow err;\n\t}),\n};\n\nconst result = parseComponentValue(tokens, options);\n\nconsole.log(result);\n```\n\n### Available functions\n\n- [`parseComponentValue`](https://www.w3.org/TR/css-syntax-3/#parse-component-value)\n- [`parseListOfComponentValues`](https://www.w3.org/TR/css-syntax-3/#parse-list-of-component-values)\n- [`parseCommaSeparatedListOfComponentValues`](https://www.w3.org/TR/css-syntax-3/#parse-comma-separated-list-of-component-values)\n\n### Utilities\n\n#### `gatherNodeAncestry`\n\nThe AST does not expose the entire ancestry of each node.\nThe walker methods do provide access to the current parent, but also not the entire ancestry.\n\nTo gather the entire ancestry for a a given sub tree of the AST you can use `gatherNodeAncestry`.\nThe result is a `Map` with the child nodes as keys and the parents as values.\nThis allows you to lookup any ancestor of any node.\n\n```js\nimport { parseComponentValue } from '@csstools/css-parser-algorithms';\n\nconst result = parseComponentValue(tokens, options);\nconst ancestry = gatherNodeAncestry(result);\n```\n\n### Options\n\n```ts\n{\n\tonParseError?: (error: ParseError) => void\n}\n```\n\n#### `onParseError`\n\nThe parser algorithms are forgiving and won't stop when a parse error is encountered.\nParse errors also aren't tokens.\n\nTo receive parsing error information you can set a callback.\n\nParser errors will try to inform you about the point in the parsing logic the error happened.\nThis tells you the kind of error.\n\n## Goals and non-goals\n\nThings this package aims to be:\n- specification compliant CSS parser\n- a reliable low level package to be used in CSS sub-grammars\n\nWhat it is not:\n- opinionated\n- fast\n- small\n- a replacement for PostCSS (PostCSS is fast and also an ecosystem)\n\n[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test\n[discord]: https://discord.gg/bUadyRwkJS\n[npm-url]: https://www.npmjs.com/package/@csstools/css-parser-algorithms\n\n[CSS Parser Algorithms]: https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms\n","publish_time":1720258455864,"maintainers":[{"name":"romainmenke","email":"romainmenke@gmail.com"},{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"jonathantneal","email":"jonathantneal@hotmail.com"}],"_cnpm_publish_time":1720258455864,"dist-tags":{"latest":"4.0.3"}}