@jridgewell/path-sorter
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@jridgewell/path-sorter

Sort paths, giving precedence to sibling, descendant, then parent directories

Installation

npm install @jridgewell/path-sorter

Usage

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',
]);

Readme

Keywords

Package Sidebar

Install

npm i @jridgewell/path-sorter

Weekly Downloads

77,683

Version

0.0.1

License

MIT

Unpacked Size

11.3 kB

Total Files

9

Last publish

Collaborators

  • jridgewell