Skip to content

Commit

Permalink
plain-text: Add trim leading
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jul 7, 2024
1 parent 3fd47f9 commit fae8f47
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/routes/plain-text/+page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PlaylistRemove from "svelte-material-icons/PlaylistRemove.svelte";
import FormatHorizontalAlignCenter from "svelte-material-icons/FormatHorizontalAlignCenter.svelte";
import AlignHorizontalRight from "svelte-material-icons/AlignHorizontalRight.svelte";
import FormatAlignMiddle from "svelte-material-icons/FormatAlignMiddle.svelte";
import AlignHorizontalLeft from "svelte-material-icons/AlignHorizontalLeft.svelte";
import { normalizeSync } from 'normalize-diacritics';

export function load() {
Expand All @@ -24,7 +25,7 @@ export function load() {
},

{
label: "Sort descending",
label: "Sort descending",
run: (text) => text.split("\n").sort().reverse().join("\n"),
icon: SortAlphabeticalDescending,
description: "Sorts all lines alphabetically, from Z to A."
Expand Down Expand Up @@ -54,26 +55,32 @@ export function load() {

"Whitespace removal": [
{
label: "Remove blank lines",
run: removeBlankLines,
icon: FormatAlignMiddle,
description: "Removes all blank lines, including those that are made only of spaces."
},

{
label: "Trim trailing & leading whitespace",
run: (text) => text.split("\n").map((line) => line.trim()).join("\n"),
icon: FormatHorizontalAlignCenter,
description: "Removes spaces at the beginning or end of each line."
label: "Trim leading",
run: removeLeadingWhitespace,
icon: AlignHorizontalLeft,
description: "Remove spaces at the beginning of each line."
},

{
label: "Trim trailing whitespace",
label: "Trim trailing",
run: removeTrailingWhitespace,
icon: AlignHorizontalRight,
description: "Remove spaces at the end of each line."
},

{
label: "Trim both",
run: (text) => text.split("\n").map((line) => line.trim()).join("\n"),
icon: FormatHorizontalAlignCenter,
description: "Removes spaces at the beginning or end of each line."
},

{
label: "Remove blank lines",
run: removeBlankLines,
icon: FormatAlignMiddle,
description: "Removes all blank lines, including those that are made only of spaces."
}
],

"Convert text case": [
Expand Down Expand Up @@ -111,6 +118,12 @@ function removeBlankLines(text) {
.join("\n");
}

function removeLeadingWhitespace(text) {
return text.split("\n")
.map((line) => line.trimStart())
.join("\n");
}

function removeTrailingWhitespace(text) {
return text.split("\n")
.map((line) => line.trimEnd())
Expand Down

0 comments on commit fae8f47

Please sign in to comment.