Sort an array of strings using regex patterns.
$ npm i --save regex-sort
const regexSort = require("regex-sort");
let result = regexSort([
"path/to/index.json",
"path/to/foo.js",
"path/to/index.min.js",
"path/to/index.js"
], [
/index\.(min\.)?js$/
, /index\.json$/
]);
console.log(result);
// [ 'path/to/index.js',
// 'path/to/index.min.js',
// 'path/to/index.json',
// 'path/to/foo.js' ]
Sort an array of strings using regex patterns.
- Array
list
: An array of strings. - Array
patterns
: An array of regular expressions used in sorting.
- Array A new array containing the sorted elements.
Have an idea? Found a bug? See how to contribute.