Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
lint glob
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed Apr 18, 2019
1 parent bf64fc6 commit f66714e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/utils/glob.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/* eslint-disable max-len */
import fs from 'fs';
import path from 'path';
import micromatch from 'micromatch';

const ls: (dir: string, filelist: string[]) => any = (dir, filelist = []): string[] => fs.readdirSync(dir)
.map(file => (fs.statSync(path.join(dir, file)).isDirectory()
const ls: (dir: string, filelist: string[]) => any = (dir, filelist = []): any[] => fs.readdirSync(dir)
.map((file: string): any[] => (fs.statSync(path.join(dir, file)).isDirectory()
? ls(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file))[0]));

const flatten = (arr: any[]): any[] => {
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val), []);
}
const flatten = (arr: any[]): any[] => arr.reduce((acc: any, val: any): any[] => (Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val)), []);

export default (path: string, glob: string) => {
const files = flatten(ls(path, []));
export default (url: string, glob: string): string[] => {
const files = flatten(ls(url, []));
return micromatch(files, glob);
};

0 comments on commit f66714e

Please sign in to comment.