-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Infer label when possible #98
Comments
I just realized I have a module for this: https://github.com/sindresorhus/fn-args Totally forgot about it. |
I'm looking into this, but unless I'm totally missing something, it doesn't feel like |
This makes me wonder, how does |
I tried using const callsites = require('callsites');
const fs = require('fs');
const ow = function(value, predicate) {
const site = callsites()[1];
const line = site.getLineNumber();
const content = fs.readFileSync(site.getFileName(), 'utf8').split('\n');
console.log(content[line - 1]);
};
const x = 'foo';
const predicate = {};
ow(x, predicate); This prints the string |
The above is exactly what we do in AVA too to get a nice output. I think Node.js-only is better than nothing. My main use-case is Node.js anyway. We just have to document it clearly. |
Would be nice to infer the
.label()
when not specified. Can be useful in environments like Node.js or browser non-minified (development).It feels moot having to define
foo
twice.The current way to do this is to parse them from
fn.toString()
: https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamicallyThe text was updated successfully, but these errors were encountered: