租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.7 KiB

3 months ago
  1. # unescape [![NPM version](https://img.shields.io/npm/v/unescape.svg?style=flat)](https://www.npmjs.com/package/unescape) [![NPM monthly downloads](https://img.shields.io/npm/dm/unescape.svg?style=flat)](https://npmjs.org/package/unescape) [![NPM total downloads](https://img.shields.io/npm/dt/unescape.svg?style=flat)](https://npmjs.org/package/unescape) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/unescape.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/unescape)
  2. > Convert HTML entities to HTML characters, e.g. `>` converts to `>`.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install --save unescape
  7. ```
  8. ## Usage
  9. ```js
  10. var decode = require('unescape');
  11. console.log(decode('<div>abc</div>'));
  12. //=> '<div>abc</div>'
  13. // get the default entities directly
  14. console.log(decode.chars);
  15. ```
  16. ## Characters
  17. For performance, this library only handles the following common entities (split into groups for backward compatibility).
  18. ### Default entities
  19. Only the following entities are converted by default.
  20. | **Character** | **Description** | **Entity Name** | **Entity Number** |
  21. | --- | --- | --- | --- |
  22. | `<` | less than | `&lt;` | `&#60;` |
  23. | `>` | greater than | `&gt;` | `&#62;` |
  24. | `&` | ampersand | `&amp;` | `&#38;` |
  25. | `"` | double quotation mark | `&quot;` | `&#34;` |
  26. | `'` | single quotation mark (apostrophe) | `&apos;` | `&#39;` |
  27. Get the default entities as an object:
  28. ```js
  29. console.log(decode.chars);
  30. ```
  31. ### Extra entities
  32. Only the following entities are converted when `'extras'` is passed as the second argument.
  33. | **Character** | **Description** | **Entity Name** | **Entity Number** |
  34. | `¢` | cent | `&cent;` | `&#162;` |
  35. | `£` | pound | `&pound;` | `&#163;` |
  36. | `¥` | yen | `&yen;` | `&#165;` |
  37. | `€` | euro | `&euro;` | `&#8364;` |
  38. | `©` | copyright | `&copy;` | `&#169;` |
  39. | `®` | registered trademark | `&reg;` | `&#174;` |
  40. Example:
  41. ```js
  42. // convert only the "extras" characters
  43. decode(str, 'extras');
  44. // get the object of `extras` characters
  45. console.log(decode.extras);
  46. ```
  47. ### All entities
  48. Convert both the defaults and extras:
  49. ```js
  50. decode(str, 'all');
  51. ```
  52. Get all entities as an object:
  53. ```js
  54. console.log(decode.all);
  55. ```
  56. ## Alternatives
  57. If you need a more robust implementation, try one of the following libraries:
  58. * [html-entities](https://github.com/mdevils/node-html-entities)
  59. * [ent](https://github.com/substack/node-ent)
  60. ## About
  61. ### Related projects
  62. * [html-elements](https://www.npmjs.com/package/html-elements): Array of all standard HTML and HTML5 elements. | [homepage](https://github.com/jonschlinkert/html-elements "Array of all standard HTML and HTML5 elements.")
  63. * [html-tag](https://www.npmjs.com/package/html-tag): Generate HTML elements from a javascript object. | [homepage](https://github.com/jonschlinkert/html-tag "Generate HTML elements from a javascript object.")
  64. * [html-toc](https://www.npmjs.com/package/html-toc): Generate a HTML table of contents using cheerio. | [homepage](https://github.com/jonschlinkert/html-toc "Generate a HTML table of contents using cheerio.")
  65. * [is-self-closing](https://www.npmjs.com/package/is-self-closing): Returns true if the given name is a HTML void element or common SVG self-closing… [more](https://github.com/jonschlinkert/is-self-closing) | [homepage](https://github.com/jonschlinkert/is-self-closing "Returns true if the given name is a HTML void element or common SVG self-closing element.")
  66. ### Contributing
  67. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  68. ### Building docs
  69. _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
  70. To generate the readme, run the following command:
  71. ```sh
  72. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  73. ```
  74. ### Running tests
  75. Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
  76. ```sh
  77. $ npm install && npm test
  78. ```
  79. ### Author
  80. **Jon Schlinkert**
  81. * [github/jonschlinkert](https://github.com/jonschlinkert)
  82. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  83. ### License
  84. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  85. Released under the [MIT License](LICENSE).
  86. ***
  87. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 04, 2017._