basant307/AI_Governance_Project
048
1# entities [](https://npmjs.org/package/entities) [](https://npmjs.org/package/entities) [](https://github.com/fb55/entities/actions/workflows/nodejs-test.yml)2 3Encode & decode HTML & XML entities with ease & speed.4 5## Features6 7- 😇 Tried and true: `entities` is used by many popular libraries; eg.8 [`htmlparser2`](https://github.com/fb55/htmlparser2), the official9 [AWS SDK](https://github.com/aws/aws-sdk-js-v3) and10 [`commonmark`](https://github.com/commonmark/commonmark.js) use it to11 process HTML entities.12- ⚡️ Fast: `entities` is the fastest library for decoding HTML entities (as13 of April 2022); see [performance](#performance).14- 🎛 Configurable: Get an output tailored for your needs. You are fine with15 UTF8? That'll save you some bytes. Prefer to only have ASCII characters? We16 can do that as well!17 18## How to…19 20### …install `entities`21 22 npm install entities23 24### …use `entities`25 26```javascript27const entities = require("entities");28 29// Encoding30entities.escapeUTF8("& ü"); // "& ü"31entities.encodeXML("& ü"); // "& ü"32entities.encodeHTML("& ü"); // "& ü"33 34// Decoding35entities.decodeXML("asdf & ÿ ü '"); // "asdf & ÿ ü '"36entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '"37```38 39## Performance40 41This is how `entities` compares to other libraries on a very basic benchmark42(see `scripts/benchmark.ts`, for 10,000,000 iterations; **lower is better**):43 44| Library | Version | `decode` perf | `encode` perf | `escape` perf |45| -------------- | ------- | ------------- | ------------- | ------------- |46| entities | `3.0.1` | 1.418s | 6.786s | 2.196s |47| html-entities | `2.3.2` | 2.530s | 6.829s | 2.415s |48| he | `1.2.0` | 5.800s | 24.237s | 3.624s |49| parse-entities | `3.0.0` | 9.660s | N/A | N/A |50 51---52 53## FAQ54 55> What methods should I actually use to encode my documents?56 57If your target supports UTF-8, the `escapeUTF8` method is going to be your best58choice. Otherwise, use either `encodeHTML` or `encodeXML` based on whether59you're dealing with an HTML or an XML document.60 61You can have a look at the options for the `encode` and `decode` methods to see62everything you can configure.63 64> When should I use strict decoding?65 66When strict decoding, entities not terminated with a semicolon will be ignored.67This is helpful for decoding entities in legacy environments.68 69> Why should I use `entities` instead of alternative modules?70 71As of April 2022, `entities` is a bit faster than other modules. Still, this is72not a very differentiated space and other modules can catch up.73 74**More importantly**, you might already have `entities` in your dependency graph75(as a dependency of eg. `cheerio`, or `htmlparser2`), and including it directly76might not even increase your bundle size. The same is true for other entity77libraries, so have a look through your `node_modules` directory!78 79> Does `entities` support tree shaking?80 81Yes! `entities` ships as both a CommonJS and a ES module. Note that for best82results, you should not use the `encode` and `decode` functions, as they wrap83around a number of other functions, all of which will remain in the bundle.84Instead, use the functions that you need directly.85 86---87 88## Acknowledgements89 90This library wouldn't be possible without the work of these individuals. Thanks91to92 93- [@mathiasbynens](https://github.com/mathiasbynens) for his explanations94 about character encodings, and his library `he`, which was one of the95 inspirations for `entities`96- [@inikulin](https://github.com/inikulin) for his work on optimized tries for97 decoding HTML entities for the `parse5` project98- [@mdevils](https://github.com/mdevils) for taking on the challenge of99 producing a quick entity library with his `html-entities` library.100 `entities` would be quite a bit slower if there wasn't any competition.101 Right now `entities` is on top, but we'll see how long that lasts!102 103---104 105License: BSD-2-Clause106 107## Security contact information108 109To report a security vulnerability, please use the110[Tidelift security contact](https://tidelift.com/security). Tidelift will111coordinate the fix and disclosure.112 113## `entities` for enterprise114 115Available as part of the Tidelift Subscription116 117The maintainers of `entities` and thousands of other packages are working with118Tidelift to deliver commercial support and maintenance for the open source119dependencies you use to build your applications. Save time, reduce risk, and120improve code health, while paying the maintainers of the exact dependencies you121use.122[Learn more.](https://tidelift.com/subscription/pkg/npm-entities?utm_source=npm-entities&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)123 