-
-
Notifications
You must be signed in to change notification settings - Fork 32
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 context info and callback to getAttributes #50
Conversation
Allows to pull in laguange dynamically
src/getAttributes.js
Outdated
if (typeof value === "function") { // Callback must return a string or a number | ||
value = value(context); // Run the provided callback and store the result | ||
} | ||
|
||
if (typeof value !== "string" && typeof value !== "number") | ||
throw new Error( | ||
`Attribute "${key}" must have a value of type string or number not "${typeof value}".` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of adding support for callbacks with context. I think we should update the wording of the error message to reflect the allowance of callbacks by saying "…must have, or evaluate to, a value of…"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense! Updating to the following:
`Attribute "${key}" must have, or evaluate to, a value of type string or number, not "${typeof value}".`
We are absolutely going for it here—appreciate this one, I love it! This will be packaged with 4.1.0 |
Allows to pull in contextual information for the syntax highlighting, and pass it to a defined function to get a dynamic output.