版博士V2.0程序
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.

readme.md 3.3 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # entities [![NPM version](http://img.shields.io/npm/v/entities.svg)](https://npmjs.org/package/entities) [![Downloads](https://img.shields.io/npm/dm/entities.svg)](https://npmjs.org/package/entities) [![Build Status](http://img.shields.io/travis/fb55/entities.svg)](http://travis-ci.org/fb55/entities) [![Coverage](http://img.shields.io/coveralls/fb55/entities.svg)](https://coveralls.io/r/fb55/entities)
  2. Encode & decode HTML & XML entities with ease & speed.
  3. ## How to…
  4. ### …install `entities`
  5. npm install entities
  6. ### …use `entities`
  7. ```javascript
  8. const entities = require("entities");
  9. //encoding
  10. entities.escape("&"); // "&"
  11. entities.encodeXML("&"); // "&"
  12. entities.encodeHTML("&"); // "&"
  13. //decoding
  14. entities.decodeXML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
  15. entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
  16. ```
  17. ## Performance
  18. This is how `entities` compares to other libraries on a very basic benchmark
  19. (see `scripts/benchmark.ts`, for 10,000,000 iterations):
  20. | Library | `decode` perf | `encode` perf | `escape` perf | Bundle size |
  21. | -------------- | ------------- | ------------- | ------------- | -------------------------------------------------------------------------- |
  22. | entities | 1.418s | 6.786s | 2.196s | ![npm bundle size](https://img.shields.io/bundlephobia/min/entities) |
  23. | html-entities | 2.530s | 6.829s | 2.415s | ![npm bundle size](https://img.shields.io/bundlephobia/min/html-entities) |
  24. | he | 5.800s | 24.237s | 3.624s | ![npm bundle size](https://img.shields.io/bundlephobia/min/he) |
  25. | parse-entities | 9.660s | N/A | N/A | ![npm bundle size](https://img.shields.io/bundlephobia/min/parse-entities) |
  26. ---
  27. ## Acknowledgements
  28. This libary wouldn't be possible without the work of these individuals. Thanks
  29. to
  30. - [@mathiasbynens](https://github.com/mathiasbynens) for his explanations
  31. about character encodings, and his library `he`, which was one of the
  32. inspirations for `entities`
  33. - [@inikulin](https://github.com/inikulin) for his work on optimized tries for
  34. decoding HTML entities for the `parse5` project
  35. - [@mdevils](https://github.com/mdevils) for taking on the challenge of
  36. producing a quick entity library with his `html-entities` library.
  37. `entities` would be quite a bit slower if there wasn't any competition.
  38. Right now `entities` is on top, but we'll see how long that lasts!
  39. ---
  40. License: BSD-2-Clause
  41. ## Security contact information
  42. To report a security vulnerability, please use the
  43. [Tidelift security contact](https://tidelift.com/security). Tidelift will
  44. coordinate the fix and disclosure.
  45. ## `entities` for enterprise
  46. Available as part of the Tidelift Subscription
  47. The maintainers of `entities` and thousands of other packages are working with
  48. Tidelift to deliver commercial support and maintenance for the open source
  49. dependencies you use to build your applications. Save time, reduce risk, and
  50. improve code health, while paying the maintainers of the exact dependencies you
  51. use.
  52. [Learn more.](https://tidelift.com/subscription/pkg/npm-entities?utm_source=npm-entities&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)