cssesc 0.1.0

Escape a string for use as a CSS string or identifier. A faithful port of the cssesc npm package. Zero deps, no_std.
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented2 out of 10 items with examples
  • Size
  • Source code size: 29.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 139.9 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1s Average build duration of successful builds.
  • all releases: 1s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/cssesc
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

cssesc

All Contributors

crates.io docs.rs CI license

Escape a string for use as a CSS string or identifier (selector).

A faithful Rust port of the widely-used cssesc npm package by Mathias Bynens.

  • Zero dependencies, #![no_std]
  • String or identifier mode, single/double quotes, wrapping, escape-everything
  • Differential-tested against the reference cssesc implementation (60k cases, all options)

Install

[dependencies]
cssesc = "0.1"

Usage

use cssesc::{cssesc, cssesc_with, Options, Quotes};

assert_eq!(cssesc("Lady Bird"), "Lady Bird");
assert_eq!(cssesc("café"), "caf\\E9");
assert_eq!(cssesc("'quotes'"), "\\'quotes\\'");

// Identifier (selector) mode escapes more, and fixes leading digits/dashes:
let id = Options::new().is_identifier(true);
assert_eq!(cssesc_with("foo.bar", &id), "foo\\.bar");
assert_eq!(cssesc_with("1up", &id), "\\31up");

// Choose quotes and wrap:
assert_eq!(cssesc_with("hi", &Options::new().quotes(Quotes::Double).wrap(true)), "\"hi\"");

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.

Thanks goes to these wonderful people:

License

Licensed under either of MIT or Apache-2.0 at your option.