Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Evaluation of specific comments //=> to show function Use Cases or internal data structure. #570

Open
josuamanuel opened this issue Dec 22, 2020 · 3 comments

Comments

@josuamanuel
Copy link

Issue description or question

New feature: Include specific kind of comment like //-> that will be evaluated. This could help to call function definitions to see example of uses. Really useful in case of libraries with functions for which as there are no invocations quokka is not useful... I usually include comments with hardcoded data structures... it would be great if instead of documentation I can include some code that reveals internal data structure, examples of use.

Sample code

// The line below will be executed by quokka.
//=> getTaxValueFromNumber(1975.08, 10.001)   //?   197.528
function getTaxValueFromNumber(x, tax) {
    try {
        if (x && !isNaN(x) && tax && !isNaN(tax)) {
            x = parseFloat(x);
            tax = parseFloat(tax);
            return getNumberRound((x / 100) * tax, countDecimals(tax));
        }
    } catch (err) {
        console.log(err);
    }
    return null;
}

function getNumberRound(x, decimals) {
  return Number(Math.round(x + 'e' + decimals) + 'e-' + decimals);
};

function countDecimals(x) {
  if (x && x % 1) {
      return x.toString().length - x.toString().indexOf('.') - 1 || 0;
  }
  return 0;
}

module.exports={getTaxValueFromNumber}

Sample repository link

N/A

Quokka.js Console Output

Code editor version

Visual Studio Code v1.?

OS name and version

OSX

@ArtemGovorov
Copy link
Member

Good idea.
While not as clean as your idea with a separate comment, right now you can do this anywhere in your file:

''//? getTaxValueFromNumber(1975.08, 10.001)

Screen Shot 2020-12-22 at 1 15 06 pm

@josuamanuel
Copy link
Author

Thanks... I am using something similar to your example. The only thing I miss is to be able to show several values within a block of comment. It will be nice if //? works inside the comment block.

image

@allforabit
Copy link

This looks similar to my suggestion: #514 Would be really amazing to have something like this. I've just renewed quokka and wallaby licenses for the year and want to try and use them more this time around. I think this would be just to feature to encourage that and make quokka completely indispensable :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants