{"id":18879735,"url":"https://github.com/loilo/node-js-php-data","last_synced_at":"2025-04-14T19:23:33.939Z","repository":{"id":38335805,"uuid":"98192953","full_name":"loilo/node-js-php-data","owner":"loilo","description":"Convert simple JS data to PHP","archived":false,"fork":false,"pushed_at":"2025-02-11T07:46:14.000Z","size":6384,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T04:05:34.121Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://loilo.github.io/node-js-php-data/","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/loilo.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,"publiccode":null,"codemeta":null}},"created_at":"2017-07-24T13:20:14.000Z","updated_at":"2025-02-11T07:45:42.000Z","dependencies_parsed_at":"2023-01-24T06:30:21.100Z","dependency_job_id":"1c83579d-020e-4d27-b8d1-1c3f57f874bd","html_url":"https://github.com/loilo/node-js-php-data","commit_stats":{"total_commits":69,"total_committers":3,"mean_commits":23.0,"dds":"0.34782608695652173","last_synced_commit":"8ef616a4974e48e21adedf92039988d338827fbc"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-js-php-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-js-php-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-js-php-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loilo%2Fnode-js-php-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loilo","download_url":"https://codeload.github.com/loilo/node-js-php-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943518,"owners_count":21186978,"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":[],"created_at":"2024-11-08T06:39:05.594Z","updated_at":"2025-04-14T19:23:33.905Z","avatar_url":"https://github.com/loilo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JS data to PHP converter\n\n[![Test status in GitHub Actions](https://img.shields.io/github/actions/workflow/status/loilo/node-js-php-data/test.yml)](https://github.com/loilo/node-js-php-data/actions/workflows/test.yml)\n[![Version on npm](https://img.shields.io/npm/v/js-php-data)](https://www.npmjs.com/package/js-php-data)\n\n\u003e This package takes a JavaScript expression and converts it into a PHP expression.\n\n[✨ Try it out in the online demo.](https://loilo.github.io/node-js-php-data/)\n\n## Why?\n\nFor a PHP-oriented full stack developer, it's quite common having to convert JavaScript (or even JSON) data into a PHP array. This is tedious to do manually and I wanted a copy\u0026paste solution.\n\nTherefore, the actual purpose of this package is its online demo, the package is merely a byproduct.\n\n## Installation\n\nInstall it from npm:\n\n```bash\nnpm install js-php-data\n```\n\n### Use in Node.js\n\n```javascript\n// In CommonJS modules\nconst jsPhpData = require('js-php-data')\n\n// In module packages\nimport jsPhpData from 'js-php-data'\n```\n\n### Use in the Browser\n\nYou can use this package in your browser. It is compiled to ES5, so it runs in all major browsers down to IE 11.\n\nThis build exposes a global `jsPhpData` function and relies on the `prettier` and `prettierPlugins.php` globals to already be loaded:\n\n```html\n\u003cscript src=\"https://unpkg.com/js-php-data/dist/js-php-data.umd.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nOnce you have somehow imported the `jsPhpData` function from this module, you can use it by passing it a value.\n\n```javascript\njsPhpData({\n  foo: 'bar',\n  baz: 5\n})\n\n/*\n[\n    'foo' =\u003e 'bar',\n    'baz' =\u003e 5\n]\n*/\n```\n\nYou may also pass some optional configuration options:\n\n---\n\n### `castToObject`\n\n**Type:** `boolean`\n\n**Default:** `false`\n\nPHP arrays are used for converted JavaScript arrays as well as JavaScript objects.\n\nThis is usually fine, but you can enable this option to make the distinction extra clear by prepending an `(object)` type cast to converted objects. This is especially useful if you want to convert the result back to JavaScript later (for example with `json_encode`), since sometimes converted arrays and objects are then indistinguishable.\n\n---\n\n### `bracketArrays`\n\n**Type:** `boolean`\n\n**Default:** `true`\n\nUse PHP's bracket `[]` notation for arrays. If set to `false`, the older/more compatible `array()` notation will be used.\n\n---\n\n### `trailingCommas`\n\n**Type:** `boolean`\n\n**Default:** `false`\n\nIf set to `true`, the last items of all arrays will have a comma appended.\n\n---\n\n### `indentation`\n\n**Type:** `number | \"tab\"`\n\n**Default:** `2`\n\nBy how many spaces arrays should be indented. If set to `\"tab\"`, one tab will be used instead.\n\n---\n\n### `quotes`\n\n**Type:** `\"single\" | \"double\"`\n\n**Default:** `\"single\"`\n\nWhich quotes to use to delimit creating strings.\n\n---\n\n### `removeUndefinedProperties`\n\n**Type:** `boolean`\n\n**Default:** `true`\n\nIf set to `true`, properties with an `undefined` value will be omitted from the output.\n\nIf set to `false`, the value will be replaced with `null`.\n\n---\n\n### `onCircular`\n\n**Type:** `\"null\" | \"nullWithComment\" | \"string\" | \"throw\"`\n\n**Default:** `\"nullWithComment\"`\n\nHow to handle circular references.\n\n- `\"null\"`: replace them with `null`\n- `\"nullWithComment\"`: replace them with `null` and a adjoining `/* CIRCULAR */` comment\n- `\"string\"`: replace them with `\"::CIRCULAR::\"`\n- `\"throw\"`: Throw an error\n\n---\n\n## Known limitations\n\nThis tool is about converting plain structures. Resolving circular dependencies or converting objects with prototypes is not supported on purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fnode-js-php-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floilo%2Fnode-js-php-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floilo%2Fnode-js-php-data/lists"}