Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve example for trimNewlines #10

Merged
merged 5 commits into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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