{"name":"parse-entities","version":"4.0.2","description":"Parse HTML character references","license":"MIT","keywords":["parse","html","character","reference","entity","entities"],"repository":{"type":"git","url":"git+https://github.com/wooorm/parse-entities.git"},"bugs":{"url":"https://github.com/wooorm/parse-entities/issues"},"funding":{"type":"github","url":"https://github.com/sponsors/wooorm"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/unist":"^2.0.0","character-entities-legacy":"^3.0.0","character-reference-invalid":"^2.0.0","decode-named-character-reference":"^1.0.0","is-alphanumerical":"^2.0.0","is-decimal":"^2.0.0","is-hexadecimal":"^2.0.0"},"devDependencies":{"@types/node":"^22.0.0","c8":"^10.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-wooorm":"^10.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.60.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","test-api":"node --conditions development test.js","test-coverage":"c8 --check-coverage --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"rules":{"@typescript-eslint/consistent-type-definitions":"off","@typescript-eslint/ban-types":"off","complexity":"off","max-depth":"off","no-bitwise":"off","unicorn/numeric-separators-style":"off","unicorn/prefer-code-point":"off"}},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"_id":"parse-entities@4.0.2","gitHead":"f95cbc9d8b383ca94996e7abcacf78a2eee66546","homepage":"https://github.com/wooorm/parse-entities#readme","_nodeVersion":"23.1.0","_npmVersion":"10.9.1","dist":{"integrity":"sha512-GG2AQYWoLgL877gQIKeRPGO1xF9+eG1ujIb5soS5gPvLQ1y2o8FL90w2QWNdf9I361Mpp7726c+lj3U0qK1uGw==","shasum":"61d46f5ed28e4ee62e9ddc43d6b010188443f159","tarball":"http://registry-npm.ywwl.com/parse-entities/download/parse-entities-4.0.2.tgz","fileCount":8,"unpackedSize":26410,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCP9CAEneH02672xpljWMN0UcBe8BfeCTnmjLXIrG4CqgIhAJnuGjctZ154St8PzxLIg9lh9Eal+XX5MShjI2YS8ate"}],"size":8195,"noattachment":false,"key":"/parse-entities/-/parse-entities-4.0.2.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parse-entities_4.0.2_1734088088569_0.09591141644053236"},"_hasShrinkwrap":false,"readme":"# parse-entities\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nParse HTML character references.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`parseEntities(value[, options])`](#parseentitiesvalue-options)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis is a small and powerful decoder of HTML character references (often called\nentities).\n\n## When should I use this?\n\nYou can use this for spec-compliant decoding of character references.\nIt’s small and fast enough to do that well.\nYou can also use this when making a linter, because there are different warnings\nemitted with reasons for why and positional info on where they happened.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install parse-entities\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {parseEntities} from 'https://esm.sh/parse-entities@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {parseEntities} from 'https://esm.sh/parse-entities@3?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {parseEntities} from 'parse-entities'\n\nconsole.log(parseEntities('alpha &amp bravo')))\n// => alpha & bravo\n\nconsole.log(parseEntities('charlie &copycat; delta'))\n// => charlie ©cat; delta\n\nconsole.log(parseEntities('echo &copy; foxtrot &#8800; golf &#x1D306; hotel'))\n// => echo © foxtrot ≠ golf 𝌆 hotel\n```\n\n## API\n\nThis package exports the identifier `parseEntities`.\nThere is no default export.\n\n### `parseEntities(value[, options])`\n\nParse HTML character references.\n\n##### `options`\n\nConfiguration (optional).\n\n###### `options.additional`\n\nAdditional character to accept (`string?`, default: `''`).\nThis allows other characters, without error, when following an ampersand.\n\n###### `options.attribute`\n\nWhether to parse `value` as an attribute value (`boolean?`, default: `false`).\nThis results in slightly different behavior.\n\n###### `options.nonTerminated`\n\nWhether to allow nonterminated references (`boolean`, default: `true`).\nFor example, `&copycat` for `©cat`.\nThis behavior is compliant to the spec but can lead to unexpected results.\n\n###### `options.position`\n\nStarting `position` of `value` (`Position` or `Point`, optional).\nUseful when dealing with values nested in some sort of syntax tree.\nThe default is:\n\n```js\n{line: 1, column: 1, offset: 0}\n```\n\n###### `options.warning`\n\nError handler ([`Function?`][warning]).\n\n###### `options.text`\n\nText handler ([`Function?`][text]).\n\n###### `options.reference`\n\nReference handler ([`Function?`][reference]).\n\n###### `options.warningContext`\n\nContext used when calling `warning` (`'*'`, optional).\n\n###### `options.textContext`\n\nContext used when calling `text` (`'*'`, optional).\n\n###### `options.referenceContext`\n\nContext used when calling `reference` (`'*'`, optional)\n\n##### Returns\n\n`string` — decoded `value`.\n\n#### `function warning(reason, point, code)`\n\nError handler.\n\n###### Parameters\n\n* `this` (`*`) — refers to `warningContext` when given to `parseEntities`\n* `reason` (`string`) — human readable reason for emitting a parse error\n* `point` ([`Point`][point]) — place where the error occurred\n* `code` (`number`) — machine readable code the error\n\nThe following codes are used:\n\n| Code | Example            | Note                                          |\n| ---- | ------------------ | --------------------------------------------- |\n| `1`  | `foo &amp bar`     | Missing semicolon (named)                     |\n| `2`  | `foo &#123 bar`    | Missing semicolon (numeric)                   |\n| `3`  | `Foo &bar baz`     | Empty (named)                                 |\n| `4`  | `Foo &#`           | Empty (numeric)                               |\n| `5`  | `Foo &bar; baz`    | Unknown (named)                               |\n| `6`  | `Foo &#128; baz`   | [Disallowed reference][invalid]               |\n| `7`  | `Foo &#xD800; baz` | Prohibited: outside permissible unicode range |\n\n#### `function text(value, position)`\n\nText handler.\n\n###### Parameters\n\n* `this` (`*`) — refers to `textContext` when given to `parseEntities`\n* `value` (`string`) — string of content\n* `position` ([`Position`][position]) — place where `value` starts and ends\n\n#### `function reference(value, position, source)`\n\nCharacter reference handler.\n\n###### Parameters\n\n* `this` (`*`) — refers to `referenceContext` when given to `parseEntities`\n* `value` (`string`) — decoded character reference\n* `position` ([`Position`][position]) — place where `source` starts and ends\n* `source` (`string`) — raw source of character reference\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types `Options`, `WarningHandler`,\n`ReferenceHandler`, and `TextHandler`.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 14.14+ and 16.0+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe: it matches the HTML spec to parse character references.\n\n## Related\n\n* [`wooorm/stringify-entities`](https://github.com/wooorm/stringify-entities)\n  — encode HTML character references\n* [`wooorm/character-entities`](https://github.com/wooorm/character-entities)\n  — info on character references\n* [`wooorm/character-entities-html4`](https://github.com/wooorm/character-entities-html4)\n  — info on HTML4 character references\n* [`wooorm/character-entities-legacy`](https://github.com/wooorm/character-entities-legacy)\n  — info on legacy character references\n* [`wooorm/character-reference-invalid`](https://github.com/wooorm/character-reference-invalid)\n  — info on invalid numeric character references\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/wooorm/parse-entities/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/parse-entities/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/parse-entities.svg\n\n[coverage]: https://codecov.io/github/wooorm/parse-entities\n\n[downloads-badge]: https://img.shields.io/npm/dm/parse-entities.svg\n\n[downloads]: https://www.npmjs.com/package/parse-entities\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/parse-entities.svg\n\n[size]: https://bundlephobia.com/result?p=parse-entities\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[warning]: #function-warningreason-point-code\n\n[text]: #function-textvalue-position\n\n[reference]: #function-referencevalue-position-source\n\n[invalid]: https://github.com/wooorm/character-reference-invalid\n\n[point]: https://github.com/syntax-tree/unist#point\n\n[position]: https://github.com/syntax-tree/unist#position\n\n[contribute]: https://opensource.guide/how-to-contribute/\n","publish_time":1734088088736,"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_cnpm_publish_time":1734088088736,"dist-tags":{"latest":"4.0.2"}}