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

cssesc vs CSS.escape #72

Closed
xing-lin opened this issue May 5, 2023 · 3 comments
Closed

cssesc vs CSS.escape #72

xing-lin opened this issue May 5, 2023 · 3 comments

Comments

@xing-lin
Copy link

xing-lin commented May 5, 2023

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

@antonmedv
Copy link
Owner

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.

@antonmedv
Copy link
Owner

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

@xing-lin
Copy link
Author

xing-lin commented May 5, 2023

I see, thanks for your answer!

@xing-lin xing-lin closed this as completed May 5, 2023
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