quokka icon indicating copy to clipboard operation
quokka copied to clipboard

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

Open josuamanuel opened this issue 4 years ago • 3 comments

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

josuamanuel avatar Dec 22 '20 02:12 josuamanuel

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

ArtemGovorov avatar Dec 22 '20 03:12 ArtemGovorov

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

josuamanuel avatar Dec 23 '20 01:12 josuamanuel

This looks similar to my suggestion: https://github.com/wallabyjs/quokka/issues/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 :-)

allforabit avatar Jan 14 '21 18:01 allforabit