teyfik-directory-loader v0.0.11
teyfik-directory-loader
Usage
Installation
npm i teyfik-directory-loaderTL; DR
For the directory structure, file contents and the usage below;
Directory structure
.
└── path
└── to
└── files
├── foo
| └── first.json
└── bar
└── second.ymlFile contents
path/to/files/foo/first.json
{
"a": 1,
"b": {
"c": 2
}
}path/to/files/bar/second.yml
{
"x": "string",
"y": false
}Usage
import directoryLoader from 'teyfik-directory-loader';
directoryLoader('path', 'to', 'files').load();Output
{
"foo": {
"first": {
"a": 1,
"b": {
"c": 2
}
}
},
"bar": {
"second": {
"x": "string",
"y": false
}
}
}Loading directories
By default, directoryLoader comes with JSON and YAML loader. You can change
these loaders with .add() and .remove() methods.
Because of there is two loaders as default, in the example below, YAML loader will be removed. You can remove loaders by using their extensions.
import directoryLoader from 'teyfik-directory-loader';
directoryLoader('path', 'to', 'files').remove('yml').load();Adding loader
Also you can add your custom loaders following this example:
directoryLoader('path', 'to', 'files')
.add('xml', (input) => parseXML(input))
.load();Removing loader
While removing a loader, any matching extension will remove the loader. Therefore both of the following approaches will work properly.
i By default, YAML loader matches both *.yml and *.yaml extensions.
Removing by yml extension:
directoryLoader('json-and-yaml-files').remove('yml').load();Removing by yaml extension:
directoryLoader('json-and-yaml-files').remove('yaml').load();Clearing all loaders
directoryLoader().clear().load();Updating open files limit
You can set maximum number of open files at a time. This is useful when you are
working with too many files. The default value is Infinity
directoryLoader('too-many-files').openFiles(5000).load();Updating max files limit
You can set a limit for total number files to be loaded. This is useful when you
are working with too many files. The default value is Infinity
directoryLoader('too-many-files').maxFiles(10000).load();