Package Exports
- textline-sorter
 - textline-sorter/dist/cjs/index.js
 
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (textline-sorter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
textline-sorter
A flexible utility for sorting lines of text.
Features
- Sort lines alphabetically, alphanumerically, or by length
 - Ascending or descending sort order
 - Option to trim whitespace
 - Option to remove empty lines
 - Option to remove duplicate lines
 
Installation
npm install textline-sorterAPI
sortLines(text: string, options: SortOptions): string
Sorts the lines of the input text based on the provided options.
Parameters
text: The input text to sort.options: An object of typeSortOptionsspecifying the sorting behavior.
SortOptions
order:"alphabetical" | "alphanumerical" | "length"- The sorting method to use.direction:"asc" | "desc"- The sort direction (ascending or descending).caseFirst:"upper" | "lower"(optional, default:"upper") - Whether upper case letters should be sorted before lower case letters ("upper") or vice versa ("lower").trimWhitespace:boolean(optional, default:false) - Whether to trim whitespace from the beginning and end of each line before sorting.removeEmptyLines:boolean(optional, default:false) - Whether to remove empty lines before sorting.removeDuplicateLines:boolean(optional, default:false) - Whether to remove duplicate lines before sorting.
Usage
Example 1: Sorting Superheroes
import { sortLines, SortOptions } from "textline-sorter";
const superheros: string = `Thor
Aquaman
Captain America
Scarlet Witch
Black Panther
Aquaman
Scarlet Witch
Cyborg
Black Widow
Captain America
Deadpool
The Flash
Spider-Man
Batman
Green Arrow
Wolverine
Green Arrow
The Flash`;
const options: SortOptions = {
  order: "alphabetical",
  direction: "asc",
  removeEmptyLines: true,
  removeDuplicateLines: true,
};
const sortedSuperheros = sortLines(superheros, options);
console.log(sortedSuperheros);Output:
Aquaman
Batman
Black Panther
Black Widow
Captain America
Cyborg
Deadpool
Green Arrow
Scarlet Witch
Spider-Man
The Flash
Thor
WolverineFor more examples, please refer to /docs/USAGE.md.
License
MIT