包详细信息

whitescape

dundalek1.2kUnlicense0.5.0

Escape whitespace characters (CommonJS, AMD and browser global compatible)

escape, whitespace, white, space

自述文件

whitescape.js

Escape whitespace characters (CommonJS, AMD and browser global compatible)

It is useful when you need to display significant whitespace, for example when visualizing parser grammars. Code points were extracted from ECMAScript spec and Wikipedia list.

Usage

npm install whitescape

var whitescape = require('whitescape');

whitescape('\b\t\n\v\f\r');
  // => "\\b\\t\\n\\v\\f\\r"
  // supports js escape sequences

whitescape('\uFEFF\u00A0');
  // => "\\uFEFF\\u00A0"
  // and also various unicode whitespace

Usage without a module loader:

<script src="whitescape.js"></script>

<script type="text/javascript">
  whitescape('\b\t\n\v\f\r');
</script>

Advanced

Whitescape does not escape space character by default. You can customize this behavior with:

whitescape.characters[' '] = '\\u0020';

Tests

npm install
npm test