1.0.3 • Published 7 years ago

glodule v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

glodule

Glodule collects global-polluting variables from scripts and exposes them as if they were module members.

Why glodule?

Glodule allows importing global-polluting traditonal libraries on module-based JS environments which do not provide a single-line solution.

Why not global option from SystemJS?

It's useful for SystemJS users but a user may use CommonJS, AMD, or even ES2015 native module syntax. Glodule provides a low-level utility to use with any supported module loaders.

Why not module loader detection, e.g. if (typeof module !== "undefined" && typeof module.exports !== "undefined")?

ES2015 module syntax does not allow dynamic detecting and exporting. Glodule allows using any supported module system without modifying existing library codes, which helps when your target libraries are from third-parties.

Use

// foo.js
// code works on traditonal module-unsupported platform
var foo = true;
// index.commonjs.js
// a shim code for CommonJS system including Node.js
module.exports = glodule("foo.js");

// index.amd.js
// a shim code for AMD system
define(glodule("foo.js"));

// index.es2015.js
// a shim code for ES2015 compatible system
export default glodule("foo.js");
// Loaders now can use index.*.js:
// CommonJS
const { foo } = require("./index.commonjs.js")

// AMD
define(["index.amd"], ({ foo }) => { });

// ES2015
import m from "./index.es2015.js";
m.foo;
1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago