-
-
Save OMGZui/c1aa4fe3e8658fa5c032d71616513df1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IdeepFindImg { | |
(path: string): Array<imageType> | |
} | |
let deepFindImg: IdeepFindImg | |
deepFindImg = (path: string) => { | |
const content = fs.readdirSync(path) | |
let images: Array<imageType> = [] | |
content.forEach(folder => { | |
const filePath = resolve(path, folder) | |
const info = fs.statSync(filePath) | |
if (info.isDirectory()) { | |
images = [...images, ...deepFindImg(filePath)] | |
} else { | |
const fileNameReg = /\.(jpe?g|png|svga)$/ | |
const shouldFormat = fileNameReg.test(filePath) | |
if (shouldFormat) { | |
const imgData = fs.readFileSync(filePath) | |
images.push({ | |
path: filePath, | |
file: imgData | |
}) | |
} | |
} | |
}) | |
return images | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment