Skip to content

anchorjs/null

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anchor/Null

The null module exports null and is used when mapping modules to an unsupported runtime.

Install

volo
$ volo add anchorjs/null

Usage

Configure

To map an unsupported module to the null module, use the map option when configuring a compatible AMD loader, such as RequireJS.

require.config({
  packages: [
    { name: 'null', main: 'null' },
  ],
  map: {
    '*': {
      'fs': 'null'
    }
  }
});

Detect Module Support

In the above example, any time the fs module is require()'d, the null module will be substituted. This is particularly useful when using Node modules in a browser context, via technologies such as JSMT.

Inside a module that uses the file system, support can be conditionally checked.

if (fs) {
  // access the file system
} else {
  // fallback behavior
}

When running in Node, the module has access to the file system. However, when running within a browser, the file system is not available and fallback behavior is executed.

Tests

To run tests in a browser, execute the Make target for the desired browser:

$ make test-chrome
$ make test-firefox
$ make test-safari

Headless tests can be executed directly from a terminal:

$ make test-phantomjs

Credits

License

The MIT License

Copyright (c) 2012-2013 Jared Hanson <http://jaredhanson.net/>