Skip to content

Commit

Permalink
Improve example for trimNewlines (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Mar 20, 2023
1 parent 40cd948 commit 3d3c62a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -5,8 +5,8 @@ Trim from the start and end of a string.
```js
import trimNewlines from 'trim-newlines';
trimNewlines('\n🦄\r\n');
//=> '🦄'
trimNewlines('\n🦄\n🦄\r\n');
//=> '🦄\n🦄'
```
*/
export function trimNewlines(string: string): string;
Expand Down
21 changes: 9 additions & 12 deletions readme.md
Expand Up @@ -2,6 +2,8 @@

> Trim [newlines](https://en.wikipedia.org/wiki/Newline) from the start and/or end of a string
Looking to trim all whitespace, not just newlines? Use `String#trim()`, `String#trimStart()`, or `String#trimEnd()`.

## Install

```
Expand All @@ -11,15 +13,15 @@ $ npm install trim-newlines
## Usage

```js
import trimNewlines from 'trim-newlines';
import {trimNewlines, trimNewlinesStart, trimNewlinesEnd} from 'trim-newlines';

trimNewlines('\n🦄\r\n');
//=> '🦄'
trimNewlines('\n🦄\n🦄\r\n');
//=> '🦄\n🦄'

trimNewlines.start('\n🦄\r\n');
trimNewlinesStart('\n🦄\r\n');
//=> '🦄\r\n'

trimNewlines.end('\n🦄\r\n');
trimNewlinesEnd('\n🦄\r\n');
//=> '\n🦄'
```

Expand All @@ -29,19 +31,14 @@ trimNewlines.end('\n🦄\r\n');

Trim from the start and end of a string.

### trimNewlines.start(string)
### trimNewlinesStart(string)

Trim from the start of a string.

### trimNewlines.end(string)
### trimNewlinesEnd(string)

Trim from the end of a string.

## Related

- [trim-left](https://github.com/sindresorhus/trim-left) - Similar to `String#trim()` but removes only whitespace on the left
- [trim-right](https://github.com/sindresorhus/trim-right) - Similar to `String#trim()` but removes only whitespace on the right.

---

<div align="center">
Expand Down
1 change: 1 addition & 0 deletions test.js
Expand Up @@ -6,6 +6,7 @@ test('main', t => {
t.is(trimNewlines(' '), ' ');
t.is(trimNewlines('\n\n\r'), '');
t.is(trimNewlines('\nx\n'), 'x');
t.is(trimNewlines('\nx\nx\n'), 'x\nx');
t.is(trimNewlines('\n\n\nx\n\n\n'), 'x');
t.is(trimNewlines('\r\nx\r\n'), 'x');
t.is(trimNewlines('\n\r\n\nx\n\r\n\n'), 'x');
Expand Down

0 comments on commit 3d3c62a

Please sign in to comment.