Git Product home page Git Product logo

teyfik-directory-loader's Introduction

teyfik-directory-loader

Usage

Installation

npm i teyfik-directory-loader

TL; DR

For the directory structure, file contents and the usage below;

Directory structure

.
└── path
  └── to
    └── files
      ├── foo
      | └── first.json
      └── bar
        └── second.yml

File 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();

teyfik-directory-loader's People

Contributors

teyfix avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.