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

add an option to render functions as their body #61

Open
scarf005 opened this issue Dec 6, 2022 · 5 comments
Open

add an option to render functions as their body #61

scarf005 opened this issue Dec 6, 2022 · 5 comments

Comments

@scarf005
Copy link

scarf005 commented Dec 6, 2022

for example:

const inspectFunction = fn => fn.toString()

inspectFunction(() => 3) 
// () => 3

inspectFunction(function(a, b, c) { return a + b + c })
// "function(a, b, c) { return a + b + c }" 
@keithamus
Copy link
Member

Thanks for the issue @scarf005. I think this is a reasonable suggestion. Perhaps we could make this the default, provided that the functions body fits within the remaining truncate length; so something like:

export default function inspectFunction(func, options) {
  const source = func.toString()
  if (source.length < options.truncate - 12) {
    return options.stylize(`[Function: ${source}]`, 'special')
  }
  const name = getFunctionName(func)
  if (!name) {
    return options.stylize('[Function]', 'special')
  }
  return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, 'special')
}

@scarf005
Copy link
Author

scarf005 commented Dec 6, 2022

alright, could i create a PR for it?

@keithamus
Copy link
Member

Please do! That would be awesome! A robust set of tests against this would be excellent too!

@scarf005
Copy link
Author

scarf005 commented Dec 6, 2022

alright. also out of context, will chai (and its related packages) consider migrating to typescript?

@keithamus
Copy link
Member

It's indeed on the radar, alongside making it a first class citizen of Deno. Any help in either direction is very welcome!

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

No branches or pull requests

2 participants