string-fix-broken-named-entities

Finds and fixes common and not so common broken named HTML entities, returns ranges array of fixes

Usage no npm install needed!

<script type="module">
  import stringFixBrokenNamedEntities from 'https://cdn.skypack.dev/string-fix-broken-named-entities';
</script>

README

string-fix-broken-named-entities

Finds and fixes common and not so common broken named HTML entities, returns ranges array of fixes

Install

The latest version is ESM only: Node 12+ is needed to use it and it must be imported instead of required. If your project is not on ESM yet and you want to use require, use an older version of this program, 5.4.0.

npm i string-fix-broken-named-entities

Quick Take

import { strict as assert } from "assert";

import { fixEnt } from "string-fix-broken-named-entities";
import { rApply } from "ranges-apply";

const source = "&nsp;x&nsp;y&nsp;";

// returns Ranges notation, see codsen.com/ranges/
assert.deepEqual(fixEnt(source), [
  [0, 5, "&nbsp;"],
  [6, 11, "&nbsp;"],
  [12, 17, "&nbsp;"],
]);

// render result from ranges using "ranges-apply":
assert.equal(rApply(source, fixEnt(source)), "&nbsp;x&nbsp;y&nbsp;");

Documentation

Please visit codsen.com for a full description of the API and even a test playground.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License

Copyright (c) 2010-2022 Roy Revelt and other contributors

ok codsen star