{"id":21188430,"url":"https://github.com/drsensor/p5-global2instance","last_synced_at":"2025-07-10T02:31:23.341Z","repository":{"id":27612904,"uuid":"112986378","full_name":"DrSensor/p5-global2instance","owner":"DrSensor","description":"Convert p5js code/snippet from global to instance mode","archived":false,"fork":false,"pushed_at":"2022-01-25T15:19:05.000Z","size":25,"stargazers_count":19,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-07T13:03:10.582Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DrSensor.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":"2017-12-04T02:45:40.000Z","updated_at":"2024-02-22T10:06:27.000Z","dependencies_parsed_at":"2022-07-27T10:18:40.777Z","dependency_job_id":null,"html_url":"https://github.com/DrSensor/p5-global2instance","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fp5-global2instance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fp5-global2instance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fp5-global2instance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fp5-global2instance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrSensor","download_url":"https://codeload.github.com/DrSensor/p5-global2instance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225613154,"owners_count":17496775,"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-20T18:44:48.423Z","updated_at":"2024-11-20T18:44:49.021Z","avatar_url":"https://github.com/DrSensor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# p5-global2instance\n[![CircleCI](https://circleci.com/gh/DrSensor/p5-global2instance.svg?style=svg)](https://circleci.com/gh/DrSensor/p5-global2instance)\n\nConvert p5js code/snippet from global to instance mode.\n\n## Install\n\n```bash\nnpm install p5-global2instance\n```\n\n## Usage\nThere are 2 away to use this script.\n\n### CLI\n\n```bash\np5-global2instance sourceCode.js\n```\n\nThis will produce __file__ `sourceCode.p5.js`.\nFor more details use `--help`\n\n```bash\nnode test.js --help\n\n  Usage: test [options] [file]\n\n\n  Options:\n\n    -o, --output [file]  Save output file to [file]\n    -p, --print          Print result to stdout\n    -h, --help           output usage information\n```\n\n### Import as module\n\nTake this example code\n\n```javascript\nconst p5Convert = require('p5-global2instance')\n\nconst sourceCode = `\nvar current;\nvar previous;\n\nfunction setup () {\n  createCanvas(720, 400);\n};\n\nfunction draw () {\n  background(0);\n};\n`\n\nlet output = p5Convert(sourceCode)\nconsole.log(output)\n```\n\nIt will output\n\n```javascript\nimport p5 from 'p5';\nexport default function (sketch) {\n  var current;\n  var previous;\n\n  sketch.setup = function () {\n    sketch.createCanvas(720, 400);\n  };\n\n  sketch.draw = function () {\n    sketch.background(0);\n  };\n}\n```\n\n#### Options\n\nYou can also pass [esprima](http://esprima.readthedocs.io/en/latest/syntactic-analysis.html?highlight=configuration) and [escodegen](https://github.com/estools/escodegen/wiki/API) options.\n\n```javascript\np5Convert(sourceCode, {\n  esprima: {},\n  escodegen: {},\n  instance: 'sketch' // default $_p\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fp5-global2instance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrsensor%2Fp5-global2instance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fp5-global2instance/lists"}