Skip to content

Commit

Permalink
docs(readme): Add FAQ section
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Aug 9, 2021
1 parent 98bb8e1 commit 14f1732
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Encode & decode HTML & XML entities with ease & speed.
```javascript
const entities = require("entities");

//encoding
entities.escape("&"); // "&"
entities.encodeXML("&"); // "&"
entities.encodeHTML("&"); // "&"
// Encoding
entities.escapeUTF8("& ü"); // "& ü"
entities.encodeXML("& ü"); // "& ü"
entities.encodeHTML("& ü"); // "& ü"

//decoding
// Decoding
entities.decodeXML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
```
Expand All @@ -37,6 +37,36 @@ This is how `entities` compares to other libraries on a very basic benchmark

---

## FAQ

> What methods should I actually use to encode my documents?
If your target supports UTF-8, the `escapeUTF8` method is going to be your best
choice. Otherwise, use either `encodeHTML` or `encodeXML` based on whether
you're dealing with an HTML or an XML document.

You can have a look at the options for the `encode` and `decode` methods to see
everything you can configure.

> Why should I use `entities` instead of alternative modules?
As of August 2021, `entities` is a bit faster than other modules. Still, this is
not a very differentiated space and other modules can catch up.

**More importantly**, you might already have `entities` in your dependency graph
(as a dependency of eg. cheerio, or htmlparser2), and including it directly
might not even increase your bundle size. The same is true for other entity
libraries, so have a look through your `node_modules` directory!

> Does `entities` support tree shaking?
This depends on your bundler, but yes, it should! Eg. recent versions of Webpack
are able to tree-shake commonjs projects, and having the `sideEffects` flag in
the `package.json` set to `false` means that your bundles should be much
smaller.

---

## Acknowledgements

This libary wouldn't be possible without the work of these individuals. Thanks
Expand Down

0 comments on commit 14f1732

Please sign in to comment.