2.2.2 • Published 1 year ago

reflection-js v2.2.2

Weekly downloads
109
License
ISC
Repository
github
Last release
1 year ago

Reflection / parsefunc is a reflection API for nodejs

Build Status Coverage Status NPM version License

Motivation

This is a very simple reflection API for javascript functions build on acorn. reflection-js is mostly designed to fit cnyks's needs.

PHPdoc/JSdoc

PHPdoc is part of PHP reflection API, that is, function described with this syntax can access their own comment. There is no standard way to attach a comment to a function in javascript. Esprima provide a way to parse the AST (and to retrieve comment) but we need a little more.

... enter the JSdoc syntax !

Attach a JSdoc to a javascript function

JSdoc pattern

foo.prototype.bar = function() /**
* This comment is valid and can describe the function behavior
* This syntax allow reflection API to work, as the comment will be serialized in the function body
*/ {
  return 43;
}


class Bar {
  async static bar() /**
  * This comment is valid and can describe the function behavior
  * This syntax allow reflection API to work, as the comment will be serialized in the function body
  */ {
    return 43;
  }

}

Usage

const parsefunc = require('reflection-js/parsefunc');
var heavyComputation = function (a, b = 1) /**
* This function computer bar
* @param {string} a Initial rotation speed
* @param {string} [b=1] this is foo
*/ {
  return a + b;
};


console.log(parsefunc(heavyComputation));

{
  "name": "heavyComputation",
  "params": {
    "a": {
      "type": "string",
      "descr": "Initial rotation speed",
      "optional": false
    },
    "b": {
      "type": "string",
      "descr": "this is foo",
      "value": "1",
      "optional": true
    }
  },
  "blocs": // all parsed @sections
  "doc": [
    "This function computer bar"
  ],
  "jsdoc": // raw comment string
}

Credits

2.2.2

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.0

2 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.3

4 years ago

2.0.4

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.5.0

4 years ago

1.4.3

6 years ago

1.4.2

7 years ago

1.4.0

8 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.2.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago