Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 27, 2021
1 parent 6851fb6 commit 06d35b7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
4 changes: 3 additions & 1 deletion index.js
@@ -1,8 +1,10 @@
/**
* Collapse whitespace to a single space.
* Collapse white space to a single space.
*
* @param {string} value
* Value to collapse white space in.
* @returns {string}
* Value with collapsed white space.
*/
export function collapseWhiteSpace(value) {
return String(value).replace(/\s+/g, ' ')
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "collapse-white-space",
"version": "2.0.0",
"description": "Replace multiple white space characters with a single space",
"description": "Collapse white space to a single space",
"license": "MIT",
"keywords": [
"collapse",
Expand Down
85 changes: 77 additions & 8 deletions readme.md
Expand Up @@ -5,19 +5,44 @@
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

Replace multiple whitespace characters with a single space.
Collapse white space to a single space.

## Install
## Contents

* [Install](#install)
* [Use](#use)
* [API](#api)
* [`collapseWhiteSpace(value)`](#collapsewhitespacevalue)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
## Install

[npm][]:
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:

```sh
npm install collapse-white-space
```

In Deno with [Skypack][]:

```js
import {collapseWhiteSpace} from 'https://cdn.skypack.dev/collapse-white-space@2?dts'
```

In browsers with [Skypack][]:

```html
<script type="module">
import {collapseWhiteSpace} from 'https://cdn.skypack.dev/collapse-white-space@2?min'
</script>
```

## Use

```js
Expand All @@ -28,13 +53,49 @@ collapseWhiteSpace('\tfoo \n\tbar \t\r\nbaz') //=> ' foo bar baz'

## API

This package exports the following identifiers: `collapseWhiteSpace`.
This package exports the following identifier: `collapseWhiteSpace`.
There is no default export.

### `collapseWhiteSpace(value)`

Replace multiple whitespace characters in `value` (`string`) with a single
space.
Collapse white space to a single space.

###### Parameters

* `value` (`string`)
– value to collapse white space in

###### Returns

`value` (`string`) – value with collapsed white space.

## Types

This package is fully typed with [TypeScript][].

## Compatibility

This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.

## Security

This package is safe.

## Related

* [`wooorm/is-whitespace-character`](https://github.com/wooorm/is-whitespace-character)
— check if a character is a white space character
* [`wooorm/detab`](https://github.com/wooorm/detab)
— convert tabs to spaces
* [`wooorm/trim-lines`](https://github.com/wooorm/trim-lines)
— remove tabs and spaces around line-breaks

## Contribute

Yes please!
See [How to Contribute to Open Source][contribute].

## License

Expand All @@ -60,6 +121,14 @@ space.

[npm]: https://docs.npmjs.com/cli/install

[skypack]: https://www.skypack.dev

[license]: license

[author]: https://wooorm.com

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[typescript]: https://www.typescriptlang.org

[contribute]: https://opensource.guide/how-to-contribute/

0 comments on commit 06d35b7

Please sign in to comment.