GithubHelp home page GithubHelp logo

isabella232 / file-register Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wiredcraft/file-register

0.0 0.0 0.0 25 KB

(Node.js) The way we organize code: break into files and folders and map to an object.

License: MIT License

JavaScript 95.13% Makefile 4.87%

file-register's Introduction

File Register

Build Status Coverage Status

(Node.js) The way we organize code: break into files and folders and map to an object.

Originally part of Carcass.

How to use

First you wanna organize your files with directories. For example say you have a group of files and directories look like this:

example/
    index.js
    lib/
        utils.js
        models/
            User.js
            ...
        views/
            index.js
            ...
        ...

Quick usage

Put this in the index.js file:

var Register = require('file-register');
var example = new Register();
example.register(__dirname, 'lib');

Now you have everything in lib/ mapped to the example.lib object.

example.lib.should.have.property('utils');
example.lib.should.have.property('models');
example.lib.should.have.property('views');

Some details (about the above example)

For files, the key is the filename without the extension, and the value is what you can get with require(file) (i.e. whatever the file exports).

example.lib.should.have.property('utils').with.type('object');
example.lib.utils.should.have.property('lorem').with.type('function');

For directories, if require() can handle it (i.e. there's an index.js or package.json etc.), we use require().

example.lib.should.have.property('views').with.type('string');

Otherwise the directory is mapped recursively.

example.lib.should.have.property('models').with.type('object');
example.lib.models.should.have.property('User').with.type('function');

For advanced usage, see

  • test/example/
  • test/example.mocha.js

Git summary

 project  : file-register
 repo age : 1 year, 1 month
 active   : 7 days
 commits  : 18
 files    : 17
 authors  :
    18  Makara Wang  100.0%

file-register's People

Contributors

makara 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.