Comparing version 0.0.1 to 0.0.2
@@ -15,2 +15,3 @@ import {crawlPath} from '../src/crawlPath' | ||
console.log(file) | ||
return null | ||
} | ||
@@ -17,0 +18,0 @@ }) |
{ | ||
"name": "crawl-path", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "src/crawlPath", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
#usage | ||
# usage | ||
@@ -10,4 +10,6 @@ ```bash | ||
let files = new Map<string, string|string[]>() | ||
import {crawlPath} from 'crawl-path' | ||
let files = new Map | ||
await crawlPath(path.join(__dirname, 'foo'), { | ||
@@ -14,0 +16,0 @@ onDir: async (_files, _path, depth) => { |
import * as fs from 'fs-extra-promise' | ||
interface crawOption { | ||
onDir: (files:string|string[], _path: string, depth: number) => void; | ||
onFile: (file:string) => void; | ||
onDir: (files: string | string[], _path: string, depth: number) => Promise<void>; | ||
onFile: (file: string) => Promise<void>; | ||
} | ||
export async function crawlPath (_path, options:crawOption, depth = 0) { | ||
if(await isDir(_path)) { | ||
depth += 1 | ||
const files = await fs.readdirAsync(_path) | ||
options.onDir(files, _path, depth) | ||
export async function crawlPath(_path, options: crawOption, depth = 0) { | ||
if (await isDir(_path)) { | ||
depth += 1 | ||
const files = await fs.readdirAsync(_path) | ||
await options.onDir(files, _path, depth) | ||
if(files) { | ||
for (let fileName of files) { | ||
const file = `${_path}/${fileName}` | ||
if (files) { | ||
for (let fileName of files) { | ||
const file = `${_path}/${fileName}` | ||
if(await isDir(file)){ | ||
await crawlPath(file, options, depth) | ||
} else if(isFile(file)) { | ||
options.onFile(file) | ||
} | ||
if (await isDir(file)) { | ||
await crawlPath(file, options, depth) | ||
} else if (await isFile(file)) { | ||
await options.onFile(file) | ||
} | ||
} | ||
} else if(await isFile(_path)) { | ||
options.onFile && options.onFile(_path) | ||
} | ||
} else if (await isFile(_path)) { | ||
await options.onFile(_path) | ||
} | ||
} | ||
@@ -29,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
23
1
2559
10
56