{"id":17901735,"url":"https://github.com/mogelbrod/widont","last_synced_at":"2025-03-23T13:31:49.164Z","repository":{"id":26896019,"uuid":"110962210","full_name":"mogelbrod/widont","owner":"mogelbrod","description":"Avoids typographical widows in strings by converting the last space/hyphens to be non-breaking","archived":false,"fork":false,"pushed_at":"2023-11-15T14:17:34.000Z","size":212,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-17T06:27:03.496Z","etag":null,"topics":["javascript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/widont","language":"JavaScript","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/mogelbrod.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}},"created_at":"2017-11-16T11:16:24.000Z","updated_at":"2024-04-16T14:54:20.000Z","dependencies_parsed_at":"2023-11-15T15:27:21.784Z","dependency_job_id":"4122d502-7c64-4e56-8ec2-2797ff709895","html_url":"https://github.com/mogelbrod/widont","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":"0.29166666666666663","last_synced_commit":"2c5e8ca914ee9d990c8993a38e38a8bb4e327dcd"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mogelbrod%2Fwidont","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mogelbrod%2Fwidont/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mogelbrod%2Fwidont/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mogelbrod%2Fwidont/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mogelbrod","download_url":"https://codeload.github.com/mogelbrod/widont/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245108225,"owners_count":20562007,"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":["javascript"],"created_at":"2024-10-28T16:03:22.400Z","updated_at":"2025-03-23T13:31:48.761Z","avatar_url":"https://github.com/mogelbrod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# widont\n\nIn typesetting, single words on the last line of a paragraph are commonly known\nas [widows](https://en.wikipedia.org/wiki/Widows_and_orphans), and are\nconsidered bad style. `widont` eliminates the issue of widows by using a\nnon-breaking space to force the last two words of a string onto the same line.\nIf the last word contains hyphens they will be converted to the non-breaking\nvariant instead.\n\n## Usage\n\n```js\nvar widont = require('widont')\n\nwidont('I dream of a world without widows')\n// =\u003e 'I dream of a world without\\u00a0widows'\n\nwidont('I like words with hyphens that stick-together')\n// =\u003e 'I like words with hyphens that stick\\u2011together'\n\nwidont('I get HTML entities instead', 'html')\n// =\u003e 'I get HTML entities\u0026nbsp;instead'\n\nwidont('I get exclamation marks', { spaces: '!!', hyphens: '??' })\n// =\u003e 'I get exclamation!!marks'\n```\n\n### In TypeScript\n\n```ts\nimport * as widont from 'widont'\n\nwidont('TypeScript says hello', 'html')\n// =\u003e 'TypeScript says\u0026nbsp;hello'\n```\n\n## API\n\n### `widont(string, [replacements='unicode'], [minWords=3])`\n\nReplaces any number of whitespace before the last word of `string` with a\nnon-breaking space, unless the last word contains hyphens in which case they\nwill be replaced (by non-breaking hyphens) instead. Trims trailing whitespace\nat the end of `string` if present. Returns non-string inputs as-is.\n\nThe optional `replacements` argument specifies what characters to use as\nreplacements. It can either be a string that maps to a set of predefined\ncharacters (`unicode`, `html` or `ascii`), or an object with the keys `space`\nand `hyphen` (both must be provided):\n\n```js\n{\n  space: '_',\n  hyphen: '~'\n}\n```\n\nA `TypeError` will be thrown for unknown or incomplete `replacements` values.\n\nThe `minWords` argument specifies the minimum number of words requires to be\npresent in the string for the replacement to be applied. It defaults to 3 to\navoid forcing strings only consisting of two words to be kept together, as that\ncould lead to them overflowing.\n\n## Origins\nThe original `widont` was created by\n[Shaun Inman](https://shauninman.com/archive/2006/08/22/widont_wordpress_plugin).\nThis implementation is based on the version in\n[Kirby CMS](https://github.com/getkirby/toolkit/blob/0ceeb44186ec0e34e45e283ddf0f99a00c192ba9/lib/str.php#L378),\nwhich extends the original by using non-breaking hyphens if the last word\ncontains hyphens.\n\n## License\n\n[MIT](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmogelbrod%2Fwidont","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmogelbrod%2Fwidont","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmogelbrod%2Fwidont/lists"}