<commit_before>jspm loader
===========

RequireJS-style ES6 dynamic module loader.

For the loader documentation read below. For a complete overview of features, see [https://jspm.io](https://jspm.io).

A ~20KB module loader written to work for ES6 modules, but that can load AMD, CommonJS and global scripts detecting the format automatically.

The loader itself is 10KB, and it is built on top of the 11KB [ES6-loader polyfill](https://github.com/ModuleLoader/es6-module-loader).

Uses RequireJS-inspired configuration options including baseURL, map, shim and custom paths (locations).

Including
---

Include `es6-loader.js` and `esprima-es6.js` (from [ES6-loader polyfill](https://github.com/ModuleLoader/es6-module-loader)) in the same folder as `require-es6.js`.

Then include it with a `<script>` tag:

```html
  <script src="path/to/jspm-loader.js"></script>
```

The 60KB Esprima parser is dynamically included when loading an ES6 module format only.

Without the parser, the polyfill and loader are roughly 20KB combined and minified.

Usage
---

### Requiring

The loader is simply a custom ES6 module loader, and can be used as one:

```javascript
  jspm.import(['some', 'modules'], function(some, modules) {
  });
```

### Setting the baseURL

Just like RequireJS, provide configuration by setting the `jspm` global variable before the script is loaded, or call the `jspm.config` function:

```javascript
  jspm.config({
    baseURL: 'http://www.mysite.com'
  });
```

### Loading Global Scripts

When loading a global script, any global variables declared are returned on the module object by the `import` function.

some-global.js:
```javascript
  window.globalVar = 'hello';
  this.anotherGlobal = 'world';
```

```javascript
  jspm.import(['some-global'], function(someGlobal) {
    console.log(someGlobal.globalVar);
    console.log(someGlobal.anotherGlobal);
  });
```

Global script dependencies can be set using the [shim configuration](#shim-configuration). The global variables declared by any dependencies will then be present on the global object.

When setting global script dependencies, the globals are carefully stored and retrieved so that multiple versions of the same global name can be used by different global scripts (for example having multiple versions of jQuery). Globals never actually touch the `window` object directly, they get a carefully managed global object passed into them ensuring the `window` object remains unchanged.

### Loading CommonJS & AMD

When loading a script that contains `AMD` or `CommonJS` module syntax, the loader will detect these statements and treat any imports and exports accordingly.

amd.js:
```javascript
  define(['./some-dep'], function(dep) {
    return { property: 'object' };
  });
```

cjs.js:
```javascript
  var dep = require('./some-dep');

  exports.property = 'object';
```

All export formats are supported by defining the module as `new Module({ 'default': exports })`. When using the module loader, this means accessing the `default` property for CommonJS
and AMD modules:

```javascript
  jspm.import(['cjs'], function(cjsModule) {
    var cjsModuleValue = cjsModule.default;
  });
```

### Loading ES6

Modules defined with ES6 syntax will be parsed with the Esprima harmony parser, which is downloaded as needed.

es6.js:
```javascript
  import { dep as d } from './some-dep';

  export var exportName = 'value';<commit_msg>AMD compatibility in readme<commit_after>jspm loader
===========

RequireJS-style ES6 dynamic module loader.

For the loader documentation read below. For a complete overview of features, see [https://jspm.io](https://jspm.io).

A ~20KB module loader written to work for ES6 modules, but that can load AMD, CommonJS and global scripts detecting the format automatically.

The loader itself is 10KB, and it is built on top of the 11KB [ES6-loader polyfill](https://github.com/ModuleLoader/es6-module-loader).

Uses RequireJS-inspired configuration options including baseURL, map, shim and custom paths (locations).

Including
---

Include `es6-loader.js` and `esprima-es6.js` (from [ES6-loader polyfill](https://github.com/ModuleLoader/es6-module-loader)) in the same folder as `require-es6.js`.

Then include it with a `<script>` tag:

```html
  <script src="path/to/jspm-loader.js"></script>
```

The 60KB Esprima parser is dynamically included when loading an ES6 module format only.

Without the parser, the polyfill and loader are roughly 20KB combined and minified.

Usage
---

### Requiring

The loader is simply a custom ES6 module loader, and can be used as one:

```javascript
  jspm.import(['some', 'modules'], function(some, modules) {
  });
```

### Setting the baseURL

Just like RequireJS, provide configuration by setting the `jspm` global variable before the script is loaded, or call the `jspm.config` function:

```javascript
  jspm.config({
    baseURL: 'http://www.mysite.com'
  });
```

### Loading Global Scripts

When loading a global script, any global variables declared are returned on the module object by the `import` function.

some-global.js:
```javascript
  window.globalVar = 'hello';
  this.anotherGlobal = 'world';
```

```javascript
  jspm.import(['some-global'], function(someGlobal) {
    console.log(someGlobal.globalVar);
    console.log(someGlobal.anotherGlobal);
  });
```

Global script dependencies can be set using the [shim configuration](#shim-configuration). The global variables declared by any dependencies will then be present on the global object.

When setting global script dependencies, the globals are carefully stored and retrieved so that multiple versions of the same global name can be used by different global scripts (for example having multiple versions of jQuery). Globals never actually touch the `window` object directly, they get a carefully managed global object passed into them ensuring the `window` object remains unchanged.

### Loading CommonJS & AMD

When loading a script that contains `AMD` or `CommonJS` module syntax, the loader will detect these statements and treat any imports and exports accordingly.

amd.js:
```javascript
  define(['./some-dep'], function(dep) {
    return { property: 'object' };
  });
```

cjs.js:
```javascript
  var dep = require('./some-dep');

  exports.property = 'object';
```

All export formats are supported by defining the module as `new Module({ 'default': exports })`. When using the module loader, this means accessing the `default` property for CommonJS
and AMD modules:

```javascript
  jspm.import(['cjs'], function(cjsModule) {
    var cjsModuleValue = cjsModule.default;
  });
```

### AMD Compatibility

The goal is to support as much of the RequireJS test suite as possible.

To create the `requirejs` and `require` globals as AMD globals, simply include the following `<script>` tag immediately after the inclusion of the jspm loader:

```html
  <script>
    require = requirejs = jspm.require;
  </script>
```

This should replicate much RequireJS functionality, and more will be covered in future.

### Loading ES6

Modules defined with ES6 syntax will be parsed with the Esprima harmony parser, which is downloaded as needed.

es6.js:
```javascript
  import { dep as d } from './some-dep';

  export var exportName = 'value';
{'fraction_non_alphanumeric': 0.10556014313239746, 'fraction_numerical': 0.006606110652353427, 'mean_word_length': 4.530441400304414, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '841529', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1954, 'n_words': 859}