jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.

cssesc

A JavaScript library for escaping CSS strings and identifiers while generating the shortest possible ASCII-only output.