Rich-Harris/devalue

Safe props

victornpb opened this issue · 1 comments

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

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!