Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jridgewell/path-sorter
Sort paths, giving precedence to sibling, descendant, then parent directories
https://github.com/jridgewell/path-sorter
Last synced: about 2 months ago
JSON representation
Sort paths, giving precedence to sibling, descendant, then parent directories
- Host: GitHub
- URL: https://github.com/jridgewell/path-sorter
- Owner: jridgewell
- License: mit
- Created: 2020-11-01T05:39:32.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T02:49:13.000Z (2 months ago)
- Last Synced: 2024-10-24T19:31:19.764Z (2 months ago)
- Language: TypeScript
- Size: 200 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# @jridgewell/path-sorter
> Sort paths, giving precedence to sibling, descendant, then parent directories
## Installation
```sh
npm install @jridgewell/path-sorter
```## Usage
```js
import pathSorter from '@jridgewell/path-sorter';const paths = [
'../foo/baz',
'../bar/baz',
'../foo',
'../bar',
'./foo/baz',
'./bar/baz',
'./foo',
'./bar',
'foo',
'bar',
];const sorted = paths.sort(pathSorter);
assert.deepEqual(sorted, [
// Non-relative paths are prioritized first
'bar',
'foo',// relative siblings paths are next, giving precedence
// _this_ directory, then 1-deep, then 2-deep, etc.
'./bar',
'./foo',
'./bar/baz',
'./foo/baz',// parent directories are last,
'../bar',
'../foo',
'../bar/baz',
'../foo/baz',
]);
```