{"id":37235586,"url":"https://github.com/thomasperi/yacssmin","last_synced_at":"2026-01-16T04:51:12.525Z","repository":{"id":57069150,"uuid":"183683587","full_name":"thomasperi/yacssmin","owner":"thomasperi","description":"Yet Another CSS Minifier","archived":false,"fork":false,"pushed_at":"2020-02-08T00:25:08.000Z","size":119,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-29T20:38:24.758Z","etag":null,"topics":["css","library","minifier","php"],"latest_commit_sha":null,"homepage":null,"language":"CSS","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/thomasperi.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":"2019-04-26T19:29:17.000Z","updated_at":"2020-02-08T00:20:03.000Z","dependencies_parsed_at":"2022-08-24T14:54:15.101Z","dependency_job_id":null,"html_url":"https://github.com/thomasperi/yacssmin","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/thomasperi/yacssmin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasperi%2Fyacssmin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasperi%2Fyacssmin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasperi%2Fyacssmin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasperi%2Fyacssmin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasperi","download_url":"https://codeload.github.com/thomasperi/yacssmin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasperi%2Fyacssmin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["css","library","minifier","php"],"created_at":"2026-01-15T04:03:25.080Z","updated_at":"2026-01-15T04:03:25.801Z","avatar_url":"https://github.com/thomasperi.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YaCSSMin\nYet Another CSS Minifier\n\n## Why?\nWhy write another CSS Minifier? Read [PHILOSOPHY.md](PHILOSOPHY.md).\n\n## Installation\n\n**Composer**  \nIn your project directory:\n\n```\ncomposer require thomasperi/yacssmin\n```\n    \n**Manually**  \nDownload [Minifier.php](https://raw.githubusercontent.com/thomasperi/yacssmin/master/src/Minifier.php) and `require` it in your PHP app:\n\n```php\nrequire '/path/to/Minifier.php';\n```\n\n## Usage\n\n```php\nuse \\ThomasPeri\\YaCSSMin\\Minifier;\n$minified_css = Minifier::minify($css);\n```\n\n### Return Value\n\nThe `minify` method returns a minified string when it successfully minifies a stylesheet. If it returns `false`, it means that the CSS code contained an un-balanced brace, bracket, parenthesis, comment, or string; or an unescaped newline inside a string. To distinguish this from the empty string, use strict comparison:\n\n```php\n$minified_css = Minifier::minify($css);\nif (false === $minified_css) {\n    // Error\n} else {\n    // Success\n}\n```\n\n### Preserving Comments\n\nThe `minify` method also accepts an optional second argument which should be an array of options.\n\nYou can selectively preserve comments by writing a callback function for filtering each comment, and passing it in as the `comments` option. This callback should accept a full comment (beginning with `/*` and ending with `*/`) and return a full comment. To preserve a comment as-is, you can just return the string that was passed in:\n\n```php\n// Preserve any comments that contain the string `@license`:\n$minified_css = Minifier::minify($css, [\n    'comments' =\u003e function ($comment) {\n        if (false !== strpos($comment, '@license')) {\n            return $comment;\n        }\n    }\n]);\n```\n\nIf it returns `null` or anything other than a valid CSS comment, the comment will be stripped from the output.\n    \n### Content Filtering\n\nThe other option available is to pass in a custom filter to alter the CSS beyond what YaCSSMin does on its own.\n\nYaCSSMin only removes whitespace and comments. It doesn't change any of the values in your CSS, like shortening color codes or rewriting URLs. (For reasons why, see [PHILOSOPHY.md](PHILOSOPHY.md).) So to do things like that, you need the `filter` option:\n\n```php\n// Preserve any comments that contain the string `@license`:\n$minified_css = Minifier::minify($css, [\n    'filter' =\u003e function ($css, \u0026$strings, \u0026$comments) {\n        // ... do stuff that modifies $css, then return the modified copy ...\n        return $css;\n    }\n]);\n```\n\nHere are the arguments that function should accept:\n\n| Argument | Description |\n| - | - |\n| `$css` | A string containing the minified stylesheet, with every string represented by the placeholder `\"_\"`, and preserved comments represented by `/*_*/`. |\n| `\u0026$strings` | An array of strings (including quotes) corresponding, in order, to the `\"_\"` placeholders. |\n| `\u0026$comments` | An array of comments corresponding, in order, to the `/*_*/` placeholders. |\n\nIf you remove a string or a comment from `$css`, be sure to also `unset` or `array_splice` it out of `\u0026$strings` or `\u0026$comments`, to keep them in sync.\n\nThere might also be comments (`/**/`) that were only emptied rather than stripped, because of weird placement. These have no counterpart in the `\u0026$comments` array.\n\n#### Example\n\nHere a stub of what rewriting URLs could look like, minus the actual rewriting part.\n\n```php\n$minified_css = Minifier::minify($css, [\n    'filter' =\u003e function ($css, \u0026$strings) {\n        $pattern = '#\"_\"|url\\((.+?)\\)#i';\n        $i = 0;\n        $rewrite = function ($url) {\n            // ... make your changes to $url here ...\n            return $url;\n        };\n        return preg_replace_callback(\n            $pattern,\n            function ($matches) use (\u0026$i, \u0026$strings, $rewrite) {\n                $match = $matches[0];\n                switch (strtolower($match)) {\n                    // Skip over strings that aren't URLs, but count them.\n                    case '\"_\"':\n                        $i++;\n                        break;\n                \n                    // Found a string that contains a URL. Rewrite the string\n                    // in the array, but leave the placeholder unchanged.\n                    case 'url(\"_\")':\n                        // Separate the URL from the quotes, rewrite the URL,\n                        // and put the quotes back on.\n                        $string = $strings[$i];\n                        $quote = substr($string, 0, 1);\n                        $url = substr($string, 1, strlen($string) - 2);\n                        $strings[$i] = $quote . $rewrite($url) . $quote;\n                        $i++;\n                        break;\n                    \n                    // Unquoted URLs aren't stashed as strings, so do the\n                    // rewrite on what was found inside url(...).\n                    default:\n                        $match = 'url(' . $rewrite($matches[1]) . ')';\n                }\n                return $match;\n            },\n            $css\n        );\n    }\n]);\n```\n\n## Pronunciation\n/ YAX min /\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasperi%2Fyacssmin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasperi%2Fyacssmin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasperi%2Fyacssmin/lists"}