Code Monkey home page Code Monkey logo

auto-load's People

Contributors

franciscop avatar leviathanbadger avatar monemihir avatar neamar avatar rricard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

auto-load's Issues

Adding options

I find myself using auto-load more and more, and there's a pattern I keep repeating and some options that would make it much more easier as per keeping my code DRY. So I think it'd be nice if auto-load would implement options by default. From my past needs, these might be:

Option Default Meaning
deep true Perform a deep recursive search in subfolders as now
js true Include javascript files (for fine-tunning)
json true Include json files (for fine-tunning)

As you can see, they are also backwards compatible as per the defaults and the current functionality. I think that accepting them as the second parameter would be nice:

var controllers = require('auto-load')('controllers', { deep: false, json: false });

What do you think of this? Might it be possible within the scope of auto-load? I can submit a pull request with the functionality described. Any other options that anyone needs?


An alternative would be accepting any random extension like extensions: ['js', 'json'], but since this uses require() internally and only js and json can be accepted I thought of only allowing them. However, a case can be made for loading files as strings (for example a .jade or a .txt as string), so it's worth noting it here. It might be worth another issue as it's extending the current implementation rather than adding options as suggested previously.

support other extensions

can we get an extension resolver function so that we can dynamically evaluate which extensions we would like to load?

More file types

Following the discussion here, it might be interesting to load more file types with auto-load. I open this issue to discuss whether this is within the scope of auto-loader or would be better suited for a package that uses auto-loader. For a folder containing the following files:

config.json
README.md
script.js
data.txt
LICENSE
hello.txt

Would it make sense to load more than just config.json and script.js? The following is proposed:

var files = require('auto-load')('files', { extensions: ['txt'] });

This would load the files with the extensions .txt and load them as strings. Only .js and .json are parsed, while other files are loaded as strings.

Pros

  • Filter by js or json in case we only want one.
  • Easy to load any kind of file with a known syntax.
  • More according to the name (auto-load could load anything, while require-all might have been better suited).

Cons

  • Inconsistent. While one file is loaded in one way, the other is loaded in a different way.
  • The library would become a bit bloated.
  • Multi-purpose for the library

why do a lowerCase on all function names

Hi,

Why do you do a lowerCase on all file names?

I want the function names/exports to be added as they are. I can understand removing of dashes and dots but why convert the case as well?

Acc to your logic:
MyFunction.js => myfunction
myFunction.js => myfunction

But I want them to stay as they are i.e
MyFunction.js => MyFunction
myFunction.js => myFunction

I don't think there should be a blanket lowercase conversion.

Are you able to put in a fix and release?

Load order and async support

Is it possible to specify load order ?

Is there async support for files that should complete a promise first ?

Relative paths

Is it possible to have relative paths, or absolute to the root, for auto-load? So it becomes easier to just include a full directory. Example:

// Relative to the root
var models = require('auto-load')('models');

// Or relative to the current file
var models = require('auto-load')('../models');

Currently the only way to do this is to use a more cumbersome notation:

var models = require('auto-load')(__dirname + '/../models');

This question in StackOverflow illustrates the issue perfectly, as it's also about readdirSync(), which is used in auto-load.

Note: I'm just proposing it since I had a really similar personal package, until I decided to find one pre-made and found this one. This is basically the only difference so I'm proposing it for improvement, but of course there's no problem typing 15-16 characters more.

Problem with typescript import

If i do
import * as autoload from 'auto-load';
i've an error "It's not a module".

I've modified your index.d.ts to :

declare module autoload {
}
declare type ModuleExports = any;
declare type AutoloadTree = {
    [key: string]: AutoloadTree | ModuleExports
};

declare interface AutoloadOptions {
    deep?: boolean,
    js?: boolean,
    json?: boolean
}

declare function autoload(baseDirectory: string, options?: AutoloadOptions): AutoloadTree;

export = autoload;

and it's works (i've moved to "}" from end to start to do "module autoload {}" and rename "auto-load" to "autoload").

I can't fork/commit/push because github isn't open from my company :(

Regards

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.