Socket
Socket
Sign inDemoInstall

es6-module-loader

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-module-loader - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

4

lib/es6-module-loader.js

@@ -1035,3 +1035,3 @@ /*

source = traceur.outputgeneration.TreeWriter.write(tree, options);
if (isBrowser)
if (isBrowser && window.btoa)
source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';

@@ -1084,3 +1084,3 @@

if (traceur)
return Promise.resolve(traceur);
return Promise.resolve(traceur || (traceur = global.traceur));

@@ -1087,0 +1087,0 @@ if (traceurPromise)

{
"name": "es6-module-loader",
"description": "An ES6 Module Loader shim",
"version": "0.4.2",
"version": "0.4.3",
"homepage": "https://github.com/ModuleLoader/es6-module-loader",

@@ -6,0 +6,0 @@ "author": {

# ES6 Module Loader Polyfill
_Fully up to date with the latest specification_
Dynamically loads ES6 modules in NodeJS and current browsers.
The new ES6 module specification defines a module system in JavaScript using `import` and `export` syntax, along with a module loader factory (`new Loader`).
The complete combined polyfill comes to 16KB minified, making it suitable for production use, provided that modules are built into ES5 making them independent of Traceur. Build workflows are currently in progress.
A separate browser specification defines the `window.System` loader, a dynamic browser loader for JavaScript modules, as well as a new `<module>` tag (`<script type="module">` for compatibility with existing browsers).
This polyfill implements the `Loader` and `Module` globals, exactly as specified in the [2013-12-02 ES6 Module Specification Draft](https://github.com/jorendorff/js-loaders/blob/e60d3651/specs/es6-modules-2013-12-02.pdf) and the `System` browser loader exactly as suggested in the [sample implementation](https://github.com/jorendorff/js-loaders/blob/964623c75d/browser-loader.js).
The complete combined polyfill comes to 16KB minified, making it suitable for production use in future, provided that modules are built into ES5 making them independent of Traceur. Build workflows are currently in progress.
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#getting-started) in all modern browsers including IE8+
* Adds support for the `<script type="module">` tag allowing inline module loading.
* Uses [Traceur](https://github.com/google/traceur-compiler) for compiling ES6 modules and syntax into ES5 in the browser with source map support
* Use as a base for creating a [custom spec-compliant module loader](#creating-a-custom-loader)
* Loader hooks can be used to [extend the System loader with custom functionality](#creating-a-custom-loader)
* Fully compatible with NodeJS allowing for spec-compliant server-side module loading
_Not yet suitable for production use while the specification is still subject to change._
See the [demo folder](https://github.com/ModuleLoader/es6-module-loader/blob/master/demo/index.html) in this repo for a working example demonstrating both module loading the module tag.
_Note that while the specification draft has been written, it is still subject to change._
## Background
The new ES6 module specification defines a module system in JavaScript using `import` and `export` syntax. For dynamically loading modules, a dynamic module loader factory is also included in the specification (`new Loader`).
A separate browser specification defines a dynamic ES6 module loader loader for the browser, `window.System`, as well as a `<script type="module">` tag for using modules.
This polyfill implements the `Loader` and `Module` globals, exactly as specified in the [2013-12-02 ES6 Module Specification Draft](https://github.com/jorendorff/js-loaders/blob/e60d3651/specs/es6-modules-2013-12-02.pdf) and the `System` browser loader exactly as suggested in the [sample implementation](https://github.com/jorendorff/js-loaders/blob/964623c75d/browser-loader.js).
## Getting Started

@@ -309,42 +311,63 @@

To use custom loader hooks, one would typically override the System loader hooks on the `System` global directly:
```javascript
// store the old normalization function
var systemNormalize = System.normalize.bind(System);
// override the normalization function
System.normalize = function(name, parentName, parentAddress) {
if (name == 'my/custom/rule')
return 'custom/name';
else
return systemNormalize(name, parentName, parentAddress);
}
```
This is the recommended way of overriding the loader.
The signatures for all the loader hooks is provided below:
To create a new loader, use the `Loader` constructor:
```javascript
var MyLoader = new Loader({
normalize: function (name, parentName, parentAddress) {
return resolvedName;
},
locate: function (load) {
// load.name is normalized name
return this.baseURL + '/' + load.name + '.js';
},
fetch: function (load) {
// return a promise. Alternatively, just use the system fetch
// promise -return System.fetch(load)
var defer = MyPromiseLibrary.createDeferred();
myXhr.get(load.address, defer.resolve, defer.reject);
return defer.promise;
},
translate: function (load) {
return load.source;
},
instantiate: function (load) {
// use standard es6 linking
return System.instantiate(load);
// provide custom linking
// useful for providing AMD and CJS support
return {
deps: ['some', 'dependencies'],
execute: function(depNameA, depNameB) {
// depNameA, depNameB normalized names
var depA = MyLoader.get(depNameA);
var depB = MyLoader.get(depNameB);
return new Module({
some: 'export'
});
}
};
}
});
function normalize(name, parentName, parentAddress) {
return resolvedName;
}
function locate(load) {
// load.name is normalized name
return this.baseURL + '/' + load.name + '.js';
}
function fetch(load) {
// return a promise. Alternatively, just use the system fetch
// promise -return System.fetch(load)
var defer = MyPromiseLibrary.createDeferred();
myXhr.get(load.address, defer.resolve, defer.reject);
return defer.promise;
}
function translate(load) {
return load.source;
}
function instantiate(load) {
// use standard es6 linking
return System.instantiate(load);
// provide custom linking
// useful for providing AMD and CommonJS support
return {
deps: ['some', 'dependencies'],
execute: function(depNameA, depNameB) {
// depNameA, depNameB normalized names
var depA = System.get(depNameA);
var depB = System.get(depNameB);
return new Module({
some: 'export'
});
}
};
}
```

@@ -410,3 +433,3 @@

* [JSPM Loader](https://github.com/jspm/jspm-loader/) is a RequireJS-style loader using our polyfill to load ES6, AMD, CommonJS and global modules
* [SystemJS](https://github.com/systemjs/systemjs) provides the `System` loader with AMD, CommonJS and global module support, as well as semver version management and a RequireJS-style plugin system and map configuration.

@@ -419,2 +442,3 @@ ## Contributing

## Release History
* 0.4.3 ES6 detection fix, Traceur runtime inclusion
* 0.4.2 promises fixes, __moduleName support, btoa language fixes, instantiation using normalized names as arguments

@@ -429,4 +453,8 @@ * 0.4.1 various tests and bug fixes, paths config, native promises support, promises update, export * support without Traceur

## Credit
Copyright (c) 2014 Luke Hoban, Addy Osmani, Guy Bedford
Promises Integration from [Promiscuous](https://github.com/RubenVerborgh/promiscuous/), Copyright (c) 2013-2014 Ruben Verborgh, MIT License
## License
Copyright (c) 2012 Luke Hoban, Addy Osmani, Guy Bedford
Licensed under the MIT license.
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