1.0.2 • Published 8 months ago

read-glob-file v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

��# 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)
1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago