{"id":13872020,"url":"https://github.com/stackotter/swift-css-parser","last_synced_at":"2025-05-13T10:30:00.754Z","repository":{"id":49376846,"uuid":"479274162","full_name":"stackotter/swift-css-parser","owner":"stackotter","description":"A lightweight CSS parser for parsing and creating CSS stylesheets","archived":false,"fork":false,"pushed_at":"2022-10-06T23:36:57.000Z","size":34,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-02T02:39:21.055Z","etag":null,"topics":["open-source","parsing","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackotter.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}},"created_at":"2022-04-08T06:37:45.000Z","updated_at":"2025-03-26T02:34:23.000Z","dependencies_parsed_at":"2022-08-25T11:40:21.248Z","dependency_job_id":null,"html_url":"https://github.com/stackotter/swift-css-parser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackotter%2Fswift-css-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackotter%2Fswift-css-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackotter%2Fswift-css-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackotter%2Fswift-css-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackotter","download_url":"https://codeload.github.com/stackotter/swift-css-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253922735,"owners_count":21984771,"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":["open-source","parsing","swift"],"created_at":"2024-08-05T23:00:32.388Z","updated_at":"2025-05-13T10:30:00.733Z","avatar_url":"https://github.com/stackotter.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# SwiftCSSParser\n\nA lightweight CSS parser for Swift that uses [cssparser](https://github.com/Sigil-Ebook/cssparser.git) (cpp) under the hood.\n\n## Basic usage\n\nHere's a simple code snippet to get you started.\n\n```swift\n// An example stylesheet (with horrible formatting)\nlet css = \"\"\"\ndiv { background: blue\n  }\n\"\"\"\n\n// Parse the stylesheet\nlet stylesheet = try Stylesheet.parse(css)\n\n// Minify\nassert(\n  stylesheet.minified())\n    ==\n  \"div{color:blue}\"\n)\n\n// Pretty print\nassert(\n  stylesheet.prettyPrinted(with: .spaces(2))\n    ==\n  \"\"\"\n  div {\n    color: blue;\n  }\n  \"\"\"\n)\n\n// Extract property\nvar background: String?\nfor statement in stylesheet.statements {\n  switch statement {\n    case .ruleSet(let ruleSet):\n      for declaration in ruleSet.declarations where declaration.property == \"background\" {\n        background = declaration.value\n        break\n      }\n    default:\n      break\n  }\n}\n\nassert(\n  background\n    ==\n  \"blue\"\n)\n```\n\n## Statements\n\nThe main CSS parsing API is built on the concept of CSS statements. It is the easiest to use and most type-safe API that SwiftCSSParser offers for parsing and creating CSS documents. However, the main limitation of the statements API is that it does not handle comments, it also may just ignore tokens that it deems to be invalid. If you find any cases where the statements generated from a document incorrectly ignore a valid token, open an issue.\n\nTo parse a document into statements, use the `Stylesheet.parseStatements(from:)` method. This is equivalent to `Stylesheet.parse(from: css).statements`.\n\n## Tokens\n\nThe tokens based API is a lower level and more simplistic version of the statements API. It is a direct Swift translation of the parsing aspect of the `cssparser` API.\n\nTo parse a document into tokens, use the `Stylesheet.parseTokens(from:)` method. The resulting token stream includes comments.\n\n## Contributing\n\n```sh\n# 1. Fork swift-css-parser\n# 2. Clone your fork\ngit clone https://github.com/yourusername/swift-css-parser \n\n# 3. Finish cloning the repository\ncd swift-css-parser\ngit submodule update --init --recursive\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackotter%2Fswift-css-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackotter%2Fswift-css-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackotter%2Fswift-css-parser/lists"}