1.0.2 • Published 8 months ago
read-glob-file v1.0.2
��# read-glob-file
Read all files in the specified folder
Install
npm i read-glob-file
Usage
readGlobFile
Read Txt or other file, By Default, the result's key is the file path.
import { readGlobFile } from 'read-glob-file'
const fileContent = readGlobFIle('./', 'a.txt')
console.log(fileContent) // { 'a.txt': 'xxx', 'src/a.txt: 'xxx' }
Read JSON file:
import { readGlobFile } from 'read-glob-file'
const fileContent = readGlobFIle('./', 'a.json', {
type: 'json',
/**
* name option is to indicate the key of result
*/
name: 'name'
})
console.log(fileContent)
Example:
{
"name": "example",
"content": "hello"
}
The output should be:
fileContent = {
example: {
name: 'example',
content: 'hello'
}
}
if json file doesn't have
name
, the key will be file path.
Ignore dirs:
import { readGlobFile } from 'read-glob-file'
const fileContent = readGlobFIle('./', 'a.txt', {
excludedDir: 'node_modules'
})
console.log(fileContent)
the excludeDir
option support minimatch, see @rollup/plugintuils to get more infomation.
Indicate depth:
import { readGlobFile } from 'read-glob-file'
const fileContent = readGlobFIle('./', 'a.txt', {
// This will ignore dir in the './' and only read 'a.txt' in the './'
depth: 0
})
console.log(fileContent)