{"id":15413401,"url":"https://github.com/wooorm/parse-entities","last_synced_at":"2025-05-15T17:05:09.523Z","repository":{"id":57319338,"uuid":"48507751","full_name":"wooorm/parse-entities","owner":"wooorm","description":"Parse HTML character references","archived":false,"fork":false,"pushed_at":"2024-12-13T11:08:06.000Z","size":188,"stargazers_count":49,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-03T08:09:41.043Z","etag":null,"topics":["character","entities","entity","html","parse","reference"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"wooorm"}},"created_at":"2015-12-23T19:32:25.000Z","updated_at":"2025-01-29T02:43:01.000Z","dependencies_parsed_at":"2023-01-21T21:40:14.483Z","dependency_job_id":"bd3bb91f-f40b-4617-b11d-774b7bb452b8","html_url":"https://github.com/wooorm/parse-entities","commit_stats":{"total_commits":102,"total_committers":6,"mean_commits":17.0,"dds":0.07843137254901966,"last_synced_commit":"96effa6ca01f9d2d6399474ad227eb5c72731462"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fparse-entities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fparse-entities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fparse-entities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fparse-entities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/parse-entities/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254081530,"owners_count":22011640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["character","entities","entity","html","parse","reference"],"created_at":"2024-10-01T16:56:55.516Z","updated_at":"2025-05-15T17:05:04.511Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","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\u003cscript type=\"module\"\u003e\n  import {parseEntities} from 'https://esm.sh/parse-entities@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {parseEntities} from 'parse-entities'\n\nconsole.log(parseEntities('alpha \u0026amp bravo')))\n// =\u003e alpha \u0026 bravo\n\nconsole.log(parseEntities('charlie \u0026copycat; delta'))\n// =\u003e charlie ©cat; delta\n\nconsole.log(parseEntities('echo \u0026copy; foxtrot \u0026#8800; golf \u0026#x1D306; hotel'))\n// =\u003e 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, `\u0026copycat` 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 \u0026amp bar`     | Missing semicolon (named)                     |\n| `2`  | `foo \u0026#123 bar`    | Missing semicolon (numeric)                   |\n| `3`  | `Foo \u0026bar baz`     | Empty (named)                                 |\n| `4`  | `Foo \u0026#`           | Empty (numeric)                               |\n| `5`  | `Foo \u0026bar; baz`    | Unknown (named)                               |\n| `6`  | `Foo \u0026#128; baz`   | [Disallowed reference][invalid]               |\n| `7`  | `Foo \u0026#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\u003c!-- Definitions --\u003e\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","funding_links":["https://github.com/sponsors/wooorm"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fparse-entities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fparse-entities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fparse-entities/lists"}