{"id":13759195,"url":"https://github.com/bashaus/prevent-widows","last_synced_at":"2025-10-10T07:41:01.171Z","repository":{"id":48055596,"uuid":"132773205","full_name":"bashaus/prevent-widows","owner":"bashaus","description":"Prevent widows from appearing in a string (includes posthtml implementation)","archived":false,"fork":false,"pushed_at":"2025-03-18T08:47:37.000Z","size":438,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T15:21:36.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bashaus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-09T14:59:20.000Z","updated_at":"2025-03-18T08:47:14.000Z","dependencies_parsed_at":"2024-01-15T03:57:33.078Z","dependency_job_id":"abb6a633-acc1-49d7-a045-ecd112cdf3a7","html_url":"https://github.com/bashaus/prevent-widows","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashaus%2Fprevent-widows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashaus%2Fprevent-widows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashaus%2Fprevent-widows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashaus%2Fprevent-widows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bashaus","download_url":"https://codeload.github.com/bashaus/prevent-widows/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248805498,"owners_count":21164340,"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":[],"created_at":"2024-08-03T13:00:48.596Z","updated_at":"2025-10-10T07:41:01.152Z","avatar_url":"https://github.com/bashaus.png","language":"TypeScript","readme":"# prevent-widows\n\n[![github actions build][img:gh-build]][url:gh-build]\n[![code coverage][img:codecov]][url:codecov]\n\nPrevent widows from appearing in a string.\n\nThis module replaces the spaces and hyphens at the end of a paragraph with\nnon-breaking spaces and non-breaking hyphens to prevent widows.\n\nIt comes with support for strings and posthtml.\n\n## Installation\n\n```\nnpm install prevent-widows\n# - or -\nyarn add prevent-widows\n```\n\n## Usage\n\nPrevent widows from appearing in a string.\n\n```javascript\nconst preventWidows = require(\"prevent-widows\");\npreventWidows(\"lorem ipsum dolar sit a met\");\n// lorem ipsum dolar sit a\u0026nbsp;met\n```\n\n```typescript\nimport preventWidows from \"prevent-widows\";\npreventWidows(\"lorem ipsum dolar sit a met\");\n// lorem ipsum dolar sit a\u0026nbsp;met\n```\n\n## Options\n\n### encoding\n\nDefines the type of output to transform the spaces and hyphens.\n\n- Since: `1.0.0`\n- Property is `Optional`\n- Default value is: `Encodings.HTML`\n- Validation rules:\n  - Must be a type of `Encoding`\n\nThis table describes how values will be transformed depending on what type of\npre-defined encoding you specify.\n\n| Encoding | Space character | Hyphen character |\n| -------- | --------------- | ---------------- |\n| html     | `\u0026nbsp;`        | `\u0026#8209;`        |\n| unicode  | `\\u00a0`        | `\\u2011`         |\n\nFor example:\n\n```typescript\npreventWidows(\"lorem ipsum dolar sit a met\", { encoding: Encodings.UNICODE });\n```\n\nAlternatively, a custom encoding can be defined using an object:\n\n```typescript\npreventWidows(\"lorem ipsum dolar sit a met\", {\n  encoding: { space: \"_\", hyphen: \"~\" },\n});\n\n// lorem ipsum dolar sit a_met\n```\n\n## posthtml\n\nThis module comes with out-of-the-box support for [posthtml][url:posthtml].\n\n### Usage\n\nThe posthtml function exposes an additional parameter: `posthtmlOptions`.\n\n```typescript\nimport posthtml from \"posthtml\";\nimport preventWidows from \"prevent-widows\";\n\nposthtml().use(preventWidows.posthtml(posthtmlOptions, preventWidowsOptions));\n```\n\n### Example\n\n```typescript\nimport posthtml from \"posthtml\";\nimport preventWidows from \"prevent-widows\";\n\n(async () =\u003e {\n  const input = \"\u003cdiv prevent-widows\u003elorem ipsum dolar sit a met\u003c/div\u003e\";\n\n  const { html } = await posthtml().use(preventWidows.posthtml()).process(input);\n\n  console.log(html);\n})();\n\n// \u003cdiv\u003elorem ipsum dolar sit a\u0026nbsp;met\u003c/div\u003e\n```\n\n### posthtml Options\n\nThe posthtml method also comes with the following options:\n\n#### attrName\n\nThe name of the attribute which identifies where widows should be prevented on\nits children.\n\n- Since: `1.0.0`\n- Property is `Optional`\n- Default value is: `prevent-widows`\n- Validation rules:\n  - Must be a valid HTML attribute name\n\n```html\n\u003cdiv prevent-widows\u003ePrevent widows\u003c/div\u003e\n```\n\n#### attrRemove\n\nWhether or not to remove the attribute (see: `attrName`) from the element after\nthe transform has been applied.\n\n- Since: `1.0.0`\n- Property is `Optional`\n- Default value is: `true`\n- Validation rules:\n  - Must be a boolean value: `true` or `false`\n\nWhen `true` and by default, this will output:\n\n```html\n\u003cdiv\u003ePrevent widows\u003c/div\u003e\n```\n\nWhen `false`, this will output:\n\n```html\n\u003cdiv prevent-widows\u003ePrevent widows\u003c/div\u003e\n```\n\n[url:posthtml]: https://github.com/posthtml/posthtml\n[img:codecov]: https://codecov.io/gh/bashaus/prevent-widows/graph/badge.svg?token=D79154VC17\n[url:codecov]: https://codecov.io/gh/bashaus/prevent-widows\n[img:gh-build]: https://github.com/bashaus/prevent-widows/actions/workflows/build.yml/badge.svg\n[url:gh-build]: https://github.com/bashaus/prevent-widows/actions/workflows/build.yml\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashaus%2Fprevent-widows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbashaus%2Fprevent-widows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashaus%2Fprevent-widows/lists"}