# string-content-sort

> sort the content inside of a string

Latest version **2.3.2** (published 2023-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install string-content-sort
pnpm add string-content-sort
yarn add string-content-sort
bun add string-content-sort
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.3.2 |
| Published | 2023-11-08 |
| First published | 2021-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | karizma |
| Maintainers | karizma |
| Keywords | string, sort, list |

## Links

- npm: https://www.npmjs.com/package/string-content-sort
- Repository: https://github.com/sixskys/scoped-sort
- Homepage: https://scopedsort.netlify.app
- Issues: https://github.com/sixskys/scoped-sort/issues
- npm.io page: https://npm.io/package/string-content-sort

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 2.3.2 (latest) — 2023-11-08
- 2.3.1 — 2022-11-12
- 2.3.0 — 2022-11-01
- 2.2.0 — 2022-10-28
- 2.1.0 — 2022-10-22
- 2.0.1 — 2022-10-22
- 2.0.0 — 2022-10-21
- 1.0.8 — 2022-08-02
- 1.0.7 — 2022-08-02
- 1.0.6 — 2022-02-06
- 1.0.5 — 2022-02-06
- 1.0.4 — 2022-02-06
- 1.0.3 — 2022-01-28
- 1.0.2 — 2022-01-28
- 1.0.1 — 2021-12-31
- … 1 more at https://npm.io/package/string-content-sort/versions

## README

# String Content Sort

## A feature rich text sorter that takes indentation into account

This npm package is part of a bigger project called
[scopedsort](https://scopedsort.netlify.app/).
[Documentation](https://scopedsort.netlify.app/docs) and
[examples](https://scopedsort.netlify.app/examples) are mainly held there.

Functions and properties will still have descriptions and typing, so you don't
need to always refer back to the documentation.

## Usage

This package exports two main functions `sort(<string>, [options])` and
`sortComments(<string>)`. There are other functions that are exported, but they
are more low-level and meant for scopedsort providers like the
[vscode extension](https://marketplace.visualstudio.com/items?itemname=karizma.scoped-sort)
or the [command line tool](https://www.npmjs.com/package/string-content-sort-cli).

```js
const { sort } = require('string-content-sort');
// or
import { sort } from 'string-content-sort';

let list = `Pokemon
Dragon Ball Z
Naruto`;

list = sort(list, { reverse: true });

assert.equals(
    list,
    `Pokemon
Naruto
Dragon Ball Z`
);
```

The first argument is the string to sort, and the second argument is an optional
object of options.

This function will throw if you have faulty options. You can turn this off by
setting `options.reportErrors` to `false`. If turned off, it will always return
a string similar to the input, possibly not what you want or expect.

```js
sort('', {
    sorter: 'random'
    // regex with random sort makes no sense
    regexFilter: /\w+/,
    reportErrors: false
});
```

NOTE: The options object will be mutated, as a lot of the properties are
shorthand for other values.

The end result of options can still be re-used and will
still produce the same output.

---

The other function, `sortComments(<string>)` serves to sort text that contain
[sort-comments](https://scopedsort.netlify.app/docs#sort-comments). It does not
return string, but instead an object with the schema:

```ts
interface {
    commentSections: {
        startLine: number;
        endLine: number | null;
        hasChanged: boolean;
    }[];
    errors: string[];
    result: string;
}
```

Example:

```js
import { sortComments } from 'string-content-sort';

const list = `Here is my list of my favorite food:

// { sort-start -s }
- ice cream
- pizza
- orange
// { sort-end }

Welp that concludes my list.`;

assert.deepEquals(sortComments(list), {
    errors: [],
    commentSections: {
        startLine: 2,
        endLine: 6,
        hasChanged: true,
    },
    result: `Here is my list of favorite food:

// { sort-start -s }
- pizza
- orange
- ice cream
// { sort-end }

Welp that concludes my list`,
});
```

## Questions & Contribution

This program might have some learning curve, so if you need any help, submit a
GitHub issue, and I'll be glad to help. If you find any bugs or want to
contribute you should also create a GitHub issue.

---
_Source: https://npm.io/package/string-content-sort · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
