1.0.0 • Published 6 years ago
path-sort2 v1.0.0
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.
1.0.0
6 years ago