{"id":13519107,"url":"https://github.com/fabiospampinato/css-simple-parser","last_synced_at":"2026-03-16T02:35:31.103Z","repository":{"id":66053392,"uuid":"237100403","full_name":"fabiospampinato/css-simple-parser","owner":"fabiospampinato","description":"A (S)CSS parser that's tiny, blazing fast and (too) simple.","archived":false,"fork":false,"pushed_at":"2023-09-24T16:28:48.000Z","size":23,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-25T12:38:54.497Z","etag":null,"topics":["ast","css","fast","parser","sass","scss","simple","small","tiny"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabiospampinato.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-01-29T23:08:18.000Z","updated_at":"2024-06-29T19:16:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"86dafeaf-b0d2-491e-ae76-e805981ff087","html_url":"https://github.com/fabiospampinato/css-simple-parser","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"00499e0166bc782dd32fc715d48c3ca555124b91"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fcss-simple-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fcss-simple-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fcss-simple-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fcss-simple-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiospampinato","download_url":"https://codeload.github.com/fabiospampinato/css-simple-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227817017,"owners_count":17824200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","css","fast","parser","sass","scss","simple","small","tiny"],"created_at":"2024-08-01T05:01:54.057Z","updated_at":"2026-03-16T02:35:31.075Z","avatar_url":"https://github.com/fabiospampinato.png","language":"JavaScript","readme":"# CSS Simple Parser\n\nA (S)CSS parser that's tiny, blazing fast and (too) simple.\n\n## Features\n\n- **Tiny**: at ~1.5kb (min + gzip) this is about as small a CSS parser as you can get.\n- **Blazing fast**: on a mid-2014 MBP it takes ~0.03ms, on average when benchmarking, to generate an AST for [this](https://github.com/fabiospampinato/css-simple-parser/blob/master/test/fixtures.js) ~500 lines CSS string, about 100x faster than PostCSS.\n- **Nesting**: nested (S)CSS rules are supported.\n\n## Caveats\n\nThe _big_ caveat is that this is not a full-blown CSS parser, it can only parse (S)CSS strings with the following limitations:\n\n- Only rule blocks are supported at the top-level, e.g. no `@charset`, `@import` etc.\n- No `{`, `}` or `;` can be used inside strings, e.g. `div[attr=\";{}\"]`, `content: \"{}\"` etc.\n- Lastly, the generated AST is quite crude and might require further processing.\n\n## Install\n\n```sh\nnpm install css-simple-parser\n```\n\n## Usage\n\n### AST\n\nThe AST (Abstract Syntax Tree) provided by this library has the following shape:\n\n```ts\ntype AST = ROOT_NODE;\n\ntype ROOT_NODE = {\n  parent: null,\n  children: NODE[]\n};\n\ntype NODE = {\n  parent: ROOT_NODE | NODE,\n  index: number,\n  indexEnd: number,\n  selector: string,\n  selectorIndex: number,\n  selectorIndexEnd: number,\n  body: string,\n  bodyIndex: number,\n  bodyIndexEnd: number,\n  children: NODE[]\n};\n```\n\n### `Parser.parse`\n\nThis method computes an AST from the given CSS string.\n\n```ts\nimport Parser from 'css-simple-parser';\n\nconst ast = Parser.parse ( '.foo {}' );\n```\n\n### `Parser.stringify`\n\nThis method computes a CSS string given an AST.\n\n```ts\nimport Parser from 'css-simple-parser';\n\nconst ast = Parser.parse ( '.foo {}' );\nconst css = Parser.stringify ( ast );\n```\n\n### `Parser.traverse`\n\nThis method calls a function with each node found in the AST, the AST is being traversed depth-first.\n\n```ts\nimport Parser from 'css-simple-parser';\n\nconst ast = Parser.parse ( '.foo {}' );\n\nParser.traverse ( ast, node =\u003e {\n  console.log ( node.selector );\n});\n```\n\n## Related\n\n- **[css-flatten](https://github.com/fabiospampinato/css-flatten)**: Flattens a nested CSS string, `\u0026` placeholders are supported too.\n- **[css-simple-minifier](https://github.com/fabiospampinato/css-simple-minifier)**: A CSS minifier that's tiny and very fast.\n\n## License\n\nMIT © Fabio Spampinato\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fcss-simple-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiospampinato%2Fcss-simple-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fcss-simple-parser/lists"}