{"id":15413454,"url":"https://github.com/wooorm/collapse-white-space","last_synced_at":"2025-04-19T11:39:59.175Z","repository":{"id":34916414,"uuid":"38967257","full_name":"wooorm/collapse-white-space","owner":"wooorm","description":"Collapse white space.","archived":false,"fork":false,"pushed_at":"2022-11-16T08:54:24.000Z","size":65,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T07:22:31.896Z","etag":null,"topics":["collapse","space","white","white-space"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"DNANUDGELTD/ArduinoLowPower","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},"funding":{"github":"wooorm"}},"created_at":"2015-07-12T15:42:42.000Z","updated_at":"2023-09-08T16:59:31.000Z","dependencies_parsed_at":"2022-09-09T12:02:22.536Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/collapse-white-space","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fcollapse-white-space","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fcollapse-white-space/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fcollapse-white-space/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fcollapse-white-space/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/collapse-white-space/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248617966,"owners_count":21134197,"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":["collapse","space","white","white-space"],"created_at":"2024-10-01T16:57:09.424Z","updated_at":"2025-04-19T11:39:59.144Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"readme":"# collapse-white-space\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\nCollapse white space.\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    *   [`collapseWhiteSpace(value[, options|style])`](#collapsewhitespacevalue-optionsstyle)\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 package that collapses multiple white space characters into one.\n\n## When should I use this?\n\nYou can use this package if you want to HTML or JavaScript (default) white space\nto a single character.\nYou can optionally drop initial and final white space.\nBy default it collapses to a single space, but optionally line endings can be\npreserved.\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 collapse-white-space\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {collapseWhiteSpace} from 'https://esm.sh/collapse-white-space@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {collapseWhiteSpace} from 'https://esm.sh/collapse-white-space@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {collapseWhiteSpace} from 'collapse-white-space'\n\ncollapseWhiteSpace('\\tfoo \\n\\tbar  \\t\\r\\nbaz') //=\u003e ' foo bar baz'\n```\n\n## API\n\nThis package exports the identifier `collapseWhiteSpace`.\nThere is no default export.\n\n### `collapseWhiteSpace(value[, options|style])`\n\nCollapse white space in `value` (`string`).\n\n##### `style`\n\nTreated as `options.style` (`'html'` or `'js'`, default: `'js'`).\n\n##### `options`\n\nConfiguration (optional).\n\n###### `options.style`\n\nStyle of white space to support (`'html'` or `'js'`, default: `'js'`).\nJavaScript white space matches the pattern `\\s`.\nHTML white space matches `[\\t\\n\\v\\f\\r ]`.\n\n###### `options.preserveLineEndings`\n\nWhether to collapse white space containing a line ending to that line ending\n(`boolean`, default: `false`).\nThe default is to collapse to a single space.\nLine endings matches the pattern `\\r?\\n|\\r`.\n\n###### `options.trim`\n\nWhether to drop white space at the start and end of `value` (`boolean`, default:\n`false`).\nThe default is to keep it.\n\n###### Returns\n\nValue with collapsed white space (`string`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types `Options` and `Style`.\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.\n\n## Related\n\n*   [`wooorm/is-whitespace-character`](https://github.com/wooorm/is-whitespace-character)\n    — check if a character is a white space character\n*   [`wooorm/detab`](https://github.com/wooorm/detab)\n    — convert tabs to spaces\n*   [`wooorm/trim-lines`](https://github.com/wooorm/trim-lines)\n    — remove tabs and spaces around line-breaks\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/collapse-white-space/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/collapse-white-space/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/collapse-white-space.svg\n\n[coverage]: https://codecov.io/github/wooorm/collapse-white-space\n\n[downloads-badge]: https://img.shields.io/npm/dm/collapse-white-space.svg\n\n[downloads]: https://www.npmjs.com/package/collapse-white-space\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/collapse-white-space.svg\n\n[size]: https://bundlephobia.com/result?p=collapse-white-space\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[contribute]: https://opensource.guide/how-to-contribute/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fcollapse-white-space","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fcollapse-white-space","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fcollapse-white-space/lists"}