# xmldefuse

> Encode the predefined XML entities (amp, lt, gt, apos, quot). Opt-out CharRef 39 for HTML. Bonus: Encode CDATA.

Latest version **0.1.2** (published 2016-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install xmldefuse
pnpm add xmldefuse
yarn add xmldefuse
bun add xmldefuse
```

Provides the commands `xmldefuse`, `xmldefuse.apos`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-08-30 |
| First published | 2016-08-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | M.K. |
| Maintainers | mk-pmb |
| Keywords | apos, CDATA, cdata, CLI, cli, defuse, encode, xmlencode, xmlentities, htmlspecialchars, entity, entities, HTML, html, XML, xml |

## Links

- npm: https://www.npmjs.com/package/xmldefuse
- Repository: https://github.com/mk-pmb/xmldefuse-js
- Homepage: https://github.com/mk-pmb/xmldefuse-js#readme
- Issues: https://github.com/mk-pmb/xmldefuse-js/issues
- npm.io page: https://npm.io/package/xmldefuse

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2016-08-30
- 0.1.1 — 2016-08-29

## README

xmldefuse
=========
Encode the [predefined XML entities][xml-predent] (amp, lt, gt, apos, quot).
Opt-out [CharRef][xml-charref] 39 for HTML. Bonus: Encode CDATA.

Usage
-----
From [test.js](test.js):
```javascript
var xmldefuse = require("xmldefuse"),
  rawXY = "X &amp& <lt< >gt> 'apos' \"quot\" Y",
  rawCD = "Have <![CDATA[ marks ]]> in ]]> text",
  eq = require("assert").strictEqual;

eq(xmldefuse(rawXY),
  "X &amp;amp&amp; &lt;lt&lt; &gt;gt&gt; &#39;apos&#39; &quot;quot&quot; Y");

eq(xmldefuse.apos(rawXY),
  "X &amp;amp&amp; &lt;lt&lt; &gt;gt&gt; &apos;apos&apos; &quot;quot&quot; Y");

eq(xmldefuse.cdata(rawXY),
  "<![CDATA[X &amp& <lt< >gt> 'apos' \"quot\" Y]]>");

eq(xmldefuse.cdata(rawCD),
  "<![CDATA[Have <![CDATA[ marks ]]]]><![CDATA[> in ]]]]><![CDATA[> text]]>");
```

CLI mode:
```bash
$ grep -oPe 'X.+Y' -m 1 test.js | xmldefuse
X &amp;amp&amp; &lt;lt&lt; &gt;gt&gt; &#39;apos&#39; \&quot;quot\&quot; Y

$ grep -oPe 'X.+Y' -m 1 test.js | xmldefuse.apos
X &amp;amp&amp; &lt;lt&lt; &gt;gt&gt; &apos;apos&apos; \&quot;quot\&quot; Y
```


Why is apos opt-in?
-------------------
The default is HTML compatibility mode because it will help visitors of
beginner webmasters who just plug the module in their HTML generator without
reading this and ignore that XML's "apos" entity is not included in the
list of [valid HTML 4 entities][html-ents].


Related
-------
  * [xmlunidefuse](https://www.npmjs.com/package/xmlunidefuse):
    Convert some additional, easily overlooked Unicode characters to CharRefs.
  * [xmldecode](https://www.npmjs.com/package/xmldecode):
    Decode the predefined XML entities, CharRefs and CDATA sections.


  [html-ents]: https://www.w3.org/TR/html4/sgml/entities.html
  [xml-charref]: https://www.w3.org/TR/REC-xml/#NT-CharRef
  [xml-predent]: https://www.w3.org/TR/REC-xml/#sec-predefined-ent


License
-------
ISC

---
_Source: https://npm.io/package/xmldefuse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
