Socket
Socket
Sign inDemoInstall

file-register

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    file-register

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


Version published
Weekly downloads
218
decreased by-28.29%
Maintainers
1
Install size
79.2 kB
Created
Weekly downloads
 

Readme

Source

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%

Keywords

FAQs

Last updated on 27 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc