{"id":51092257,"url":"https://github.com/cssmagic/sorl2pac","last_synced_at":"2026-06-24T03:36:19.001Z","repository":{"id":365674147,"uuid":"1270236494","full_name":"cssmagic/sorl2pac","owner":"cssmagic","description":"To convert SwitchyOmega rule lists (*.sorl) to PAC script. | 将 SwitchyOmega 规则列表（*.sorl）转换为 PAC 脚本。","archived":false,"fork":false,"pushed_at":"2026-06-18T10:05:23.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-18T12:09:28.820Z","etag":null,"topics":["proxy","sorl","switchyomega"],"latest_commit_sha":null,"homepage":"","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/cssmagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-15T14:13:34.000Z","updated_at":"2026-06-18T10:05:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cssmagic/sorl2pac","commit_stats":null,"previous_names":["cssmagic/sorl2pac"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cssmagic/sorl2pac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssmagic%2Fsorl2pac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssmagic%2Fsorl2pac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssmagic%2Fsorl2pac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssmagic%2Fsorl2pac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cssmagic","download_url":"https://codeload.github.com/cssmagic/sorl2pac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssmagic%2Fsorl2pac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34716325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["proxy","sorl","switchyomega"],"created_at":"2026-06-24T03:36:18.382Z","updated_at":"2026-06-24T03:36:18.989Z","avatar_url":"https://github.com/cssmagic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"English | [中文](README.zh.md)\n\n# sorl2pac\n\n\u003e To convert SwitchyOmega rule lists (`*.sorl`) to PAC script.\n\n\n\n## Usage\n\n```js\nimport { sorl2pac } from \"sorl2pac\";\n\nconst pacSource = sorl2pac(sorlText, {\n\tmatched: \"DIRECT\",\n\tunmatched: \"PROXY 127.0.0.1:7890\",\n});\n```\n\n`pacSource` is a complete PAC script. It contains an internal `match(host)` helper and a standard `FindProxyForURL(url, host)` function.\n\n```js\nfunction FindProxyForURL(url, host) {\n\treturn match(host) ? \"DIRECT\" : \"PROXY 127.0.0.1:7890\";\n}\n```\n\n\n\n## API\n\n```ts\nfunction sorl2pac(\n\tsorl: string,\n\tresults: {\n\t\tmatched: string;\n\t\tunmatched: string;\n\t},\n): string;\n```\n\n- `sorl` must be a string containing a supported SwitchyOmega rule list.\n- `results.matched` is returned by `FindProxyForURL()` when `match(host)` is `true`.\n- `results.unmatched` is returned when `match(host)` is `false`.\n- `match(host)` is generated inside the PAC script. It is not an extra package export.\n\n`sorl2pac()` throws `TypeError` for invalid API arguments and `SyntaxError` for unsupported rule-list syntax.\n\n\n\n## Supported Syntax\n\nThis package intentionally supports a small SwitchyOmega new-format subset:\n\n- `[SwitchyOmega Conditions]`\n- blank lines\n- `;` comment lines\n- `@note` lines\n- bare `HostWildcardCondition` rules, such as `*.example.com`\n- host wildcard prefixes: `HostWildcard:`, `HostWildcardCondition:`, `Host:`, `H:`, `W:`, `HW:`\n- `!` exclusive rules\n\nUnsupported syntax fails instead of being ignored, including old `#BEGIN` rule lists, `@with result`, `+profile`, URL conditions, IP conditions, time conditions, and AutoProxy syntax.\n\n\n\n## Matching Behavior\n\n- Rules are checked from top to bottom.\n- A normal rule match returns `true`.\n- An exclusive rule match returns `false`.\n- No match returns `false`.\n- An empty rule list is valid and always returns `false`.\n- `*.abc.com` matches both `abc.com` and `sub.abc.com`.\n- `**.abc.com` matches `sub.abc.com` but not `abc.com`.\n\nBecause `results` is configurable, callers can use the same rules for whitelist or blacklist behavior.\n\n```js\nconst whitelistPac = sorl2pac(sorlText, {\n\tmatched: \"DIRECT\",\n\tunmatched: \"PROXY 127.0.0.1:7890\",\n});\n\nconst blacklistPac = sorl2pac(sorlText, {\n\tmatched: \"PROXY 127.0.0.1:7890\",\n\tunmatched: \"DIRECT\",\n});\n```\n\n\n\n***\n\n## License\n\n\u003e Any code contributed to this project is considered authorized for commercial use by the project authors and their affiliated companies and distributed under this project's license.\n\u003e\n\u003e 任何贡献到本项目的代码，均视为授权本项目作者及其关联公司用于商业用途，并可按本项目协议进行分发。\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssmagic%2Fsorl2pac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcssmagic%2Fsorl2pac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssmagic%2Fsorl2pac/lists"}