Socket
Socket
Sign inDemoInstall

trim-newlines

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trim-newlines - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

75

index.d.ts

@@ -1,42 +0,51 @@

declare const trimNewlines: {
/**
Trim from the start and end of a string.
// Source: https://github.com/sindresorhus/type-fest/blob/main/source/internal.d.ts#L49
type Newline =
| '\u{A}' // '\n'
| '\u{D}' // '\r'
;
@example
```js
import trimNewlines from 'trim-newlines';
// Source: https://github.com/sindresorhus/type-fest/blob/main/source/trim.d.ts
type TrimStart<S extends string> = S extends `${Newline}${infer R}` ? TrimStart<R> : S;
trimNewlines('\n🦄\r\n');
//=> '🦄'
```
*/
(string: string): string;
type TrimEnd<S extends string> = S extends `${infer R}${Newline}` ? TrimEnd<R> : S;
/**
Trim from the start of a string.
export type Trim<S extends string> = TrimStart<TrimEnd<S>>;
@example
```js
import trimNewlines from 'trim-newlines';
/**
Trim from the start and end of a string.
trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'
```
*/
start(string: string): string;
@example
```js
import trimNewlines from 'trim-newlines';
/**
Trim from the end of a string.
trimNewlines('\n🦄\n🦄\r\n');
//=> '🦄\n🦄'
```
*/
export function trimNewlines<S extends string>(string: S): Trim<S>;
@example
```js
import trimNewlines from 'trim-newlines';
/**
Trim from the start of a string.
trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
```
*/
end(string: string): string;
};
@example
```js
import trimNewlines from 'trim-newlines';
export default trimNewlines;
trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'
```
*/
export function trimNewlinesStart<S extends string>(string: S): TrimStart<S>;
/**
Trim from the end of a string.
@example
```js
import trimNewlines from 'trim-newlines';
trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
```
*/
export function trimNewlinesEnd<S extends string>(string: S): TrimEnd<S>;

@@ -1,2 +0,2 @@

export default function trimNewlines(string) {
export function trimNewlines(string) {
let start = 0;

@@ -16,3 +16,3 @@ let end = string.length;

trimNewlines.start = string => {
export function trimNewlinesStart(string) {
const end = string.length;

@@ -26,5 +26,5 @@ let start = 0;

return start > 0 ? string.slice(start, end) : string;
};
}
trimNewlines.end = string => {
export function trimNewlinesEnd(string) {
let end = string.length;

@@ -37,2 +37,2 @@

return end < string.length ? string.slice(0, end) : string;
};
}
{
"name": "trim-newlines",
"version": "4.0.2",
"version": "4.1.0",
"description": "Trim newlines from the start and/or end of a string",

@@ -42,6 +42,6 @@ "license": "MIT",

"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.39.1"
"ava": "^5.2.0",
"tsd": "^0.28.0",
"xo": "^0.53.1"
}
}

@@ -5,2 +5,4 @@ # trim-newlines

Looking to trim all whitespace, not just newlines? Use `String#trim()`, `String#trimStart()`, or `String#trimEnd()`.
## Install

@@ -15,11 +17,11 @@

```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🦄'

@@ -34,15 +36,10 @@ ```

### 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.
---

@@ -49,0 +46,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc