Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file-register

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
248
increased by14.29%
Maintainers
1
Weekly downloads
 
Created
Source

File Register

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

Originally part of Carcass.

How to use

See test/example/index.js and test/example.mocha.js for more details.

For example say you have a group of files and directories looks like this:

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

Quick usage

It exports a class, and you can get an instance:

var Register = require('file-register');
var example = new Register();

Assuming the code is in example/index.js:

var path = require('path');
example.register(path.resolve(__dirname, 'lib'));

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

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

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.should.have.property('utils').with.type('object');
example.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.should.have.property('views').with.type('string');

Otherwise the directory is mapped recursively.

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

Using the proto

TODO

API change from carcass.proto.register

TODO

Keywords

FAQs

Package last updated on 30 Dec 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc