antonmedv/finder

cssesc vs CSS.escape

Closed this issue · 3 comments

Hi, Could you please tell me what is the difference between cssesc and CSS.escape ? Is it possible to replace cssesc with CSS.escape ?

Both cssesc and CSS.escape are JavaScript functions that are used to escape special characters in CSS strings. However, there are some differences between them.

cssesc is a third-party library that provides a more comprehensive set of escape sequences than CSS.escape. cssesc can escape a wider range of characters, including control characters, Unicode characters, and invalid CSS identifiers. It also offers more configuration options, such as specifying the character encoding or the style of the escape sequence.

On the other hand, CSS.escape is a built-in function that was introduced in the CSS Object Model (CSSOM) specification. It is designed specifically for escaping CSS identifiers and can handle only ASCII characters. CSS.escape is intended to be used in environments where the CSSOM is available, such as in a browser environment.

In most cases, CSS.escape should be sufficient for escaping CSS identifiers in a browser environment. However, if you need to escape a wider range of characters or if you're working outside of a browser environment, you may want to consider using cssesc.

In terms of whether it's possible to replace cssesc with CSS.escape, it depends on the specific use case. If you only need to escape ASCII characters in a browser environment, then you can use CSS.escape instead of cssesc. However, if you need to escape a wider range of characters or if you're working outside of a browser environment, then you will need to use cssesc.

https://caniuse.com/mdn-api_css_escape Probably we can do the switch.

I see, thanks for your answer!