{"id":16048930,"url":"https://github.com/devongovett/to-ast","last_synced_at":"2025-03-16T07:32:34.024Z","repository":{"id":29744391,"uuid":"33287902","full_name":"devongovett/to-ast","owner":"devongovett","description":"Converts JavaScript objects to equivalent ASTs","archived":false,"fork":false,"pushed_at":"2019-08-12T04:20:31.000Z","size":120,"stargazers_count":34,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T05:51:13.152Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devongovett.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-02T03:48:06.000Z","updated_at":"2024-03-23T00:02:06.000Z","dependencies_parsed_at":"2022-08-28T09:12:47.426Z","dependency_job_id":null,"html_url":"https://github.com/devongovett/to-ast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fto-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fto-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fto-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devongovett%2Fto-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devongovett","download_url":"https://codeload.github.com/devongovett/to-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806052,"owners_count":20350775,"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-10-09T00:11:23.179Z","updated_at":"2025-03-16T07:32:33.696Z","avatar_url":"https://github.com/devongovett.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# to-ast\n\nThis module converts JavaScript objects to an equivalent abstract syntax tree representation, \ncompatible with the [Mozilla Parser API](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API).\nYou can use it to generate JavaScript source code from objects, using \n[escodegen](https://github.com/estools/escodegen).\n\n## Usage\n\nInstall with npm:\n\n    npm install to-ast\n\nHere's a simple example:\n\n```javascript\n\nvar toAST = require('to-ast');\nvar escodegen = require('escodegen');\n\n// get an AST from a number...\ntoAST(2) //=\u003e { type: 'Literal', value: 2 }\n\n// or if you want a source string...\nescodegen.generate(toAST(2)) //=\u003e '2'\n```\n\n## Supported types\n\n* undefined\n* null\n* number, string, and boolean literals\n* functions\n* Node buffers\n* arrays\n* String, Number, and Boolean object wrappers\n* typed arrays and array buffers\n* dates\n* errors\n* regular expressions\n* object literals\n\n## Custom types\n\nMost built-in JavaScript types as supported out of the box, but if you want to override the behavior for\nyour particular object, you can provide a `toAST` method on your object:\n\n```javascript\nvar toAST = require('to-ast');\nvar escodegen = require('escodegen');\n\nfunction Person(name) {\n  this.name = name;\n}\n\nPerson.prototype.toAST = function() {\n  return {\n    type: 'NewExpression',\n    callee: { type: 'Identifier', name: 'Person' },\n    arguments: [{ type: 'Literal', value: this.name }]\n  };\n};\n\nescodegen.generate(toAST(new Person('Devon'))) //=\u003e \"new Person('Devon')\"\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevongovett%2Fto-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevongovett%2Fto-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevongovett%2Fto-ast/lists"}