Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"tabWidth": 2,
"useTabs": false,
"proseWrap": "preserve",
"embeddedLanguageFormatting": "off",
"singleQuote": true,
"trailingComma": "all"
}
73 changes: 11 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,10 @@ const result = cleanstring(`
// Result: "Any literal\nwhich needs to be split\non multiple lines for readability."

// Custom prefix example
const markdown = cleanstring(
`
>This is a markdown quote
>with multiple lines
`,
{ prefix: '>' },
);
// Result: "This is a markdown quote\nwith multiple lines"

// Custom prefix with trailing space example (note the prefix contains a space)
const markdown = cleanstring(
`
const markdown = cleanstring(`
> This is a markdown quote
> with multiple lines
`,
{ prefix: '> ' },
);
`, { prefix: '> ' });
// Result: "This is a markdown quote\nwith multiple lines"
```

Expand Down Expand Up @@ -79,62 +66,22 @@ const sql = cleanstring(`

```typescript
// Markdown quotes with > prefix
const quote = cleanstring(
`
> This is a quote
> from someone famous
`,
{ prefix: '>' },
);
// Result: " This is a quote\n from someone famous"

// Shell comments with # prefix
const script = cleanstring(
`
# This is a shell script
# with multiple comment lines
`,
{ prefix: '#' },
);
// Result: " This is a shell script\n with multiple comment lines"

// List items with * prefix
const list = cleanstring(
`
* First item
* Second item
* Third item
`,
{ prefix: '*' },
);
// Result: " First item\n Second item\n Third item"
const quote = cleanstring(`
>This is a quote
>from someone famous
`, { prefix: '>' });
// Result: "This is a quote\nfrom someone famous"
```

### Multi-character prefixes for space stripping

If you want to strip a space after the prefix (reproducing the old behavior), include the space as part of the prefix:

```typescript
// Using "> " (greater than + space) strips the space after >
const cleanQuote = cleanstring(
`
const cleanQuote = cleanstring(`
> This is a quote
> with multiple lines
`,
{ prefix: '> ' },
);
`, { prefix: '> ' });
// Result: "This is a quote\nwith multiple lines"

// Using "| " (pipe + space) strips the space after |
const cleanCode = cleanstring(
`
| function example() {
| return 'hello world';
| }
`,
{ prefix: '| ' },
);
// Result: "function example() {\n return 'hello world';\n}"
```

### Mixed content with prefix
Expand All @@ -151,6 +98,8 @@ const script = cleanstring(`

### Without prefixes

Note that leading/trailing blank lines are still stripped.

```typescript
const text = cleanstring(`

Expand Down