load-goblin

Mass loading of files, supporting JSON and YAML parsing

Usage no npm install needed!

<script type="module">
  import loadGoblin from 'https://cdn.skypack.dev/load-goblin';
</script>

README

load-goblin

NPM Version Build Status

Mass loading of files, supporting JSON and YAML parsing

Getting started

First install the package:

npm i load-goblin

Then, use it to load your files:

import { resolve } from 'path'
import { loadFiles } from 'load-goblin'

function getPath(rootDir = '') {
  return resolve(__dirname, 'files', rootDir)
}

const filesLoaded = await loadFiles({
  rootDirectory: getPath(),
  recursively: true,
  filter: '*/abc*.json',
})

Supported config options

rootDirectory - required parameter. Specifies full path for a directory from which loading will be initiated; recursively - optional parameter. If set to true, loading will include subdirectories; filter - optional parameter. Can be either a simple text matching rule (supporting * for any amount of any symbols in the path), or a (path: string) => boolean matcher function.

Output

Loader returns an array of entities, where each entry represents one file. Format:

{
    "content": "data=content",
    "name": "root.txt",
    "path": "C:/sources/node/load-goblin/test/files",
}

Note that JSON and YAML files are automatically parsed into objects. All other files are returned as text.