path-sort2

1.0.0 • Public • Published

path-sort2

Sort a list of file/directory paths, such that something like this:

Example

const pathSort = require('path-sort2');
 
let files = [
  'a/c',
  'a/a/a',
  'b/b',
  'b/a/2/a',
  'b/a/1/b',
  'a/b',
  'b/a/1/a',
  'a/a/b',
  'b/a/2/b',
  'c',
];
 
let sortedFiles = pathSort(files);
// [
//   'a/b',
//   'a/c',
//   'a/a/a',
//   'a/a/b',
//   'b/b',
//   'b/a/1/a',
//   'b/a/1/b',
//   'b/a/2/a',
//   'b/a/2/b',
//   'c',
// ]

Install

npm install path-sort2

Usage

const pathSort = require('path-sort2');
 
pathSort(files); // sorted files
pathSort(files, '/'); // custom seperator (defaults to `path.sep`)
 
files.sort(pathSort.standalone()); // sorted files
files.sort(pathSort.standalone('/')); // custom seperator (defaults to `path.sep`)

Note: Using pathSort.standalone() is a little bit slower, but is sometimes more convenient.

/path-sort2/

    Package Sidebar

    Install

    npm i path-sort2

    Weekly Downloads

    207

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    3.42 kB

    Total Files

    4

    Last publish

    Collaborators

    • thejameskyle