{"id":18544743,"url":"https://github.com/131/reflection","last_synced_at":"2025-06-14T18:03:59.596Z","repository":{"id":57352124,"uuid":"44472177","full_name":"131/reflection","owner":"131","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-31T14:35:46.000Z","size":40,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-10T12:08:36.587Z","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/131.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":"2015-10-18T09:21:11.000Z","updated_at":"2024-05-31T14:35:48.000Z","dependencies_parsed_at":"2025-04-09T19:36:33.296Z","dependency_job_id":"71ab6b0b-711e-4a39-ba46-6a4591ce3e30","html_url":"https://github.com/131/reflection","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/131/reflection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Freflection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Freflection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Freflection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Freflection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/131","download_url":"https://codeload.github.com/131/reflection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/131%2Freflection/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259433962,"owners_count":22857055,"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-06T20:17:27.982Z","updated_at":"2025-06-14T18:03:59.028Z","avatar_url":"https://github.com/131.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reflection / parsefunc is a reflection API for nodejs\r\n\r\n[![Build Status](https://github.com/131/reflection/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/131/reflection/actions/workflows/tests.yml)\r\n[![Coverage Status](https://coveralls.io/repos/github/131/reflection/badge.svg?branch=master)](https://coveralls.io/github/131/reflection?branch=master)\r\n[![NPM version](https://img.shields.io/npm/v/reflection-js.svg)](https://www.npmjs.com/package/reflection-js)\r\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)\r\n\r\n# Motivation\r\nThis is a very simple reflection API for javascript functions build on [acorn](https://www.npmjs.com/package/acorn).  [reflection-js](https://github.com/131/reflection) is mostly designed to fit [cnyks](https://github.com/131/cnyks)'s needs.\r\n\r\n\r\n\r\n\r\n# PHPdoc/JSdoc\r\nPHPdoc is part of PHP reflection API, that is, function described with this syntax can access their own comment.\r\nThere is no standard way to attach a comment to a function in javascript.\r\nEsprima provide a way to parse the AST (and to retrieve comment) but we need a little more.\r\n\r\n... enter the JSdoc syntax !\r\n\r\n\r\n# Attach a JSdoc to a javascript function\r\n## JSdoc pattern\r\n\r\n```\r\nfoo.prototype.bar = function() /**\r\n* This comment is valid and can describe the function behavior\r\n* This syntax allow reflection API to work, as the comment will be serialized in the function body\r\n*/ {\r\n  return 43;\r\n}\r\n\r\n\r\nclass Bar {\r\n  async static bar() /**\r\n  * This comment is valid and can describe the function behavior\r\n  * This syntax allow reflection API to work, as the comment will be serialized in the function body\r\n  */ {\r\n    return 43;\r\n  }\r\n\r\n}\r\n```\r\n# Usage\r\n```\r\nconst parsefunc = require('reflection-js/parsefunc');\r\nvar heavyComputation = function (a, b = 1) /**\r\n* This function computer bar\r\n* @param {string} a Initial rotation speed\r\n* @param {string} [b=1] this is foo\r\n*/ {\r\n  return a + b;\r\n};\r\n\r\n\r\nconsole.log(parsefunc(heavyComputation));\r\n\r\n{\r\n  \"name\": \"heavyComputation\",\r\n  \"params\": {\r\n    \"a\": {\r\n      \"type\": \"string\",\r\n      \"descr\": \"Initial rotation speed\",\r\n      \"optional\": false\r\n    },\r\n    \"b\": {\r\n      \"type\": \"string\",\r\n      \"descr\": \"this is foo\",\r\n      \"value\": \"1\",\r\n      \"optional\": true\r\n    }\r\n  },\r\n  \"blocs\": // all parsed @sections\r\n  \"doc\": [\r\n    \"This function computer bar\"\r\n  ],\r\n  \"jsdoc\": // raw comment string\r\n}\r\n```\r\n\r\n\r\n# Credits \r\n* [131](https://github.com/131)\r\n\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Freflection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F131%2Freflection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F131%2Freflection/lists"}