{"id":13672918,"url":"https://github.com/searchfe/ts2php","last_synced_at":"2025-08-04T15:35:15.157Z","repository":{"id":35650587,"uuid":"171823726","full_name":"searchfe/ts2php","owner":"searchfe","description":"Typescript to PHP Transpiler. ","archived":false,"fork":false,"pushed_at":"2024-07-04T06:51:16.000Z","size":4634,"stargazers_count":95,"open_issues_count":16,"forks_count":19,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-22T12:10:38.319Z","etag":null,"topics":["php","typescript"],"latest_commit_sha":null,"homepage":"https://searchfe.github.io/ts2php/","language":"TypeScript","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/searchfe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2019-02-21T07:38:58.000Z","updated_at":"2025-07-22T11:27:10.000Z","dependencies_parsed_at":"2024-11-09T12:11:24.466Z","dependency_job_id":"7e677e58-78e0-4e93-931a-131791858d61","html_url":"https://github.com/searchfe/ts2php","commit_stats":{"total_commits":501,"total_committers":18,"mean_commits":"27.833333333333332","dds":0.6327345309381238,"last_synced_commit":"0da3a494ec11526d82503bcb2d43e31f49a299f1"},"previous_names":[],"tags_count":111,"template":false,"template_full_name":null,"purl":"pkg:github/searchfe/ts2php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchfe%2Fts2php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchfe%2Fts2php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchfe%2Fts2php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchfe%2Fts2php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/searchfe","download_url":"https://codeload.github.com/searchfe/ts2php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/searchfe%2Fts2php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268715661,"owners_count":24295352,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"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":["php","typescript"],"created_at":"2024-08-02T09:01:57.255Z","updated_at":"2025-08-04T15:35:15.128Z","avatar_url":"https://github.com/searchfe.png","language":"TypeScript","readme":"# ts2php\n\n**under development**\n\nTypeScript 转 PHP\n\nA Compiler which can compile TypeScript to PHP.\n\n![Language](https://img.shields.io/badge/-TypeScript-blue.svg)\n[![Build Status](https://travis-ci.com/searchfe/ts2php.svg?branch=master)](https://travis-ci.org/searchfe/ts2php)\n[![npm package](https://img.shields.io/npm/v/ts2php.svg)](https://www.npmjs.org/package/ts2php)\n[![npm downloads](http://img.shields.io/npm/dm/ts2php.svg)](https://www.npmjs.org/package/ts2php)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/searchfe/ts2php)\n\n- [ts2php](#ts2php)\n  - [Usage](#usage)\n    - [compiler](#compiler)\n    - [runtime](#runtime)\n    - [CLI](#cli)\n    - [update ts2php version](#update-ts2php-version)\n  - [Features](#features)\n    - [Javascript Syntax](#javascript-syntax)\n    - [Core JavaScript API](#core-javascript-api)\n  - [Thanks to](#thanks-to)\n\n## Usage\n\n### compiler\n\n```javascript\nimport {compile} from 'ts2php';\n\nconst result = compile(filePath, options);\n```\n\n### runtime\n\n\u003e 部分功能依赖一个 PHP 的类库，需要在 PHP 工程中引入\n\n\u003e Some features are implemented by a PHP helper class, which need to be included in your PHP\n code.\n\n```php\nrequire_once(\"/path/to/ts2php/dist/runtime/Ts2Php_Helper.php\");\n```\n\n### CLI\n\nQuick Start：\n\n```bash\n$ npm i -g ts2php\n$ ts2php ./a.ts                   # 编译输出到 stdout\n```\n\n使用[配置][options]并输出到文件：\n\n```bash\n$ cat config.js\nmodule.exports = {\n  emitHeader: false\n};\n$ ts2php -c config.js src/ -o output/\n```\n\n更多选项：\n\n```bash\n$ ts2php --show-diagnostics       # 输出诊断信息\n$ ts2php --emit-header            # 输出头部信息\n$ ts2php -h                       # 更多功能请查看帮助\n```\n\n### update ts2php version\n\nSame TS code with different version of ts2php may result to different PHP code. When updating the version of ts2php, we should check the result PHP code manually. To simplify this process, we recommend to use [ts2php-diff-checker][ts2php-diff-checker]. Specify two version of ts2php, and some source TS code, [ts2php-diff-checker][ts2php-diff-checker] will generate diff info directly.\n\n```sh\nts2php-check \u003cpattern\u003e \u003cold-version\u003e \u003cnew-version\u003e [destination]\n```\n\n## Features\n\n### Javascript Syntax\n\n- [`for`/`for of`/`for in`](./test/features/ForStatement.md)\n- [`if`/`else if`/`else`](./test/features/IfStatement.md)\n- [`switch`](./test/features/SwitchStatement.md)\n- [`while`/`do while`](./test/features/WhileStatement.md)\n- [`Class`](./test/features/Class.md)\n- [`typeof`](./test/features/GlobalApi.md)\n- [`delete`](./test/features/GlobalApi.md)\n- [`destructuring`](./test/features/Destructuring.md)\n- [`template string`](./test/features/template.md)\n- [`object computed property`](./test/features/ComputedPropertyName.md)\n- [`object shorthand property`](./test/features/ShorthandPropertyAssignment.md)\n- [`enum`](./test/features/EnumDeclaration.md)\n- [`anonymous function inherit variables`](./test/features/inheritedVariables.md)\n- [`rest function arguments`](./test/features/spreadExpression.md)\n- [`spread`](./test/features/spreadExpression.md)\n- [`exception`](./test/features/exception.md)\n\nFor more, see feature test markdowns: [Javascript Syntax](./test/features)\n\n### Core JavaScript API\n\n- parseInt **只接收一个参数**\n- parseFloat\n- encodeURIComponent\n- decodeURIComponent\n- encodeURI\n- __dirname\n- __filename\n- Date\n  - Date.now\n  - Date.prototype.getTime\n  - Date.prototype.getDate\n  - Date.prototype.getDay\n  - Date.prototype.getFullYear\n  - Date.prototype.getHours\n  - Date.prototype.getMinutes\n  - Date.prototype.getMonth\n  - Date.prototype.getSeconds\n  - Date.prototype.setDate\n  - Date.prototype.setFullYear\n  - Date.prototype.setHours\n  - Date.prototype.setMinutes\n  - Date.prototype.setMonth\n  - Date.prototype.setSeconds\n  - Date.prototype.setTime\n- Object\n  - Object.assign\n  - Object.keys\n  - Object.values\n  - Object.freeze\n  - Object.prototype.hasOwnProperty\n- JSON\n  - JSON.stringify **只接收一个参数**\n  - JSON.parse **只接收一个参数**\n- console\n  - console.log\n  - console.info **转成 var_dump**\n  - console.error\n- String\n  - String.prototype.replace **第二个参数只支持 string，不支持 Function**\n  - String.prototype.trim\n  - String.prototype.trimRight\n  - String.prototype.trimLeft\n  - String.prototype.toUpperCase\n  - String.prototype.toLowerCase\n  - String.prototype.split\n  - String.prototype.indexOf\n  - String.prototype.substring\n  - String.prototype.repeat\n  - String.prototype.startsWidth\n  - String.prototype.endsWidth\n  - String.prototype.includes\n  - String.prototype.padStart\n  - String.prototype.match **只支持正则和字符串匹配**\n- Array\n  - Array.isArray\n  - Array.prototype.length\n  - Array.prototype.filter **回调函数只接收第一个参数**\n  - Array.prototype.push\n  - Array.prototype.pop\n  - Array.prototype.shift\n  - Array.prototype.unshift\n  - Array.prototype.concat\n  - Array.prototype.reverse\n  - Array.prototype.splice\n  - Array.prototype.reverse\n  - Array.prototype.map\n  - Array.prototype.forEach\n  - Array.prototype.indexOf\n  - Array.prototype.join\n  - Array.prototype.some\n  - Array.prototype.every\n  - Array.prototype.find\n  - Array.prototype.findIndex\n  - Array.prototype.sort\n- Number\n  - Number.isInterger\n  - Number.prototype.toFixed\n  - Number.prototype.toString\n- Math\n  - Math.abs\n  - Math.acos\n  - Math.acosh\n  - Math.asin\n  - Math.asinh\n  - Math.atan\n  - Math.atanh\n  - Math.atan2\n  - Math.cbrt\n  - Math.ceil\n  - Math.clz32\n  - Math.cos\n  - Math.cosh\n  - Math.exp\n  - Math.expm1\n  - Math.floor\n  - Math.hypot\n  - Math.log\n  - Math.log1p\n  - Math.log10\n  - Math.max\n  - Math.min\n  - Math.pow\n  - Math.random\n  - Math.round\n  - Math.sin\n  - Math.sinh\n  - Math.sqrt\n  - Math.tan\n  - Math.tanh\n\n## Thanks to\n\nBased on [Typescript](https://github.com/Microsoft/TypeScript) compiler\n\n[options]: https://searchfe.github.io/ts2php/interfaces/ts2phpoptions.html\n[ts2php-diff-checker]: https://github.com/meixg/ts2php-diff-checker\n","funding_links":[],"categories":["Other Language Targets","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsearchfe%2Fts2php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsearchfe%2Fts2php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsearchfe%2Fts2php/lists"}