Skip to content

Instantly share code, notes, and snippets.

@OMGZui
Created November 18, 2022 09:39
Show Gist options
  • Save OMGZui/c1aa4fe3e8658fa5c032d71616513df1 to your computer and use it in GitHub Desktop.
Save OMGZui/c1aa4fe3e8658fa5c032d71616513df1 to your computer and use it in GitHub Desktop.
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