From 3d3c62a9fc99e8eb0771cda599688bcf730df01f Mon Sep 17 00:00:00 2001 From: Tommy Date: Mon, 20 Mar 2023 12:22:18 -0500 Subject: [PATCH] Improve example for `trimNewlines` (#10) --- index.d.ts | 4 ++-- readme.md | 21 +++++++++------------ test.js | 1 + 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index c5fdb78..ec82718 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; diff --git a/readme.md b/readme.md index 2b8561b..0fb6ea3 100644 --- a/readme.md +++ b/readme.md @@ -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 ``` @@ -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šŸ¦„' ``` @@ -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. - ---
diff --git a/test.js b/test.js index f452673..bb7c3bb 100644 --- a/test.js +++ b/test.js @@ -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');