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

Safe props #3

Closed
victornpb opened this issue Mar 14, 2018 · 1 comment
Closed

Safe props #3

victornpb opened this issue Mar 14, 2018 · 1 comment

Comments

@victornpb
Copy link

Could you elaborate what is the purpose of the safeProps function and what it the regex for?

@Rich-Harris
Copy link
Owner

If an object has a property called foo, you can reference it using dot notation, i.e. obj.foo. But if the property is called something like yar-bar then you have to quote it and use array notation, i.e. obj["yar-bar"]. The regex determines which kind of property it is (in 99% of cases, at least — it's possible to have certain other characters in a dot notation property, but it's costly to figure out so devalue errs on the side of caution), and safeProp returns a string like .foo or ["yar-bar"] that can be appended to obj. Hope this clarifies!

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